
<!DOCTYPE html>
<html lang="en" class="RFC STD">
<head>
<meta charset="utf-8">
<meta content="Common,Greek,Han,Latin" name="scripts">
<meta content="initial-scale=1.0" name="viewport">
<title>RFC 8949: Concise Binary Object Representation (CBOR)</title>
<meta content="Carsten Bormann" name="author">
<meta content="Paul Hoffman" name="author">
<meta content="
       The Concise Binary Object Representation (CBOR) is a data format whose design
goals include the
possibility of extremely small code size, fairly small message size, and
extensibility without the
need for version negotiation. These design goals make it different from earlier
binary
serializations such as ASN.1 and MessagePack. 
        This document obsoletes RFC 7049, providing editorial improvements, new 
   details, and errata fixes while keeping full compatibility with 
   the interchange format of RFC 7049.  It does not create a new version
   of the format.  
    " name="description">
<meta content="xml2rfc 3.5.0" name="generator">
<meta content="parser" name="keyword">
<meta content="decoder" name="keyword">
<meta content="encoder" name="keyword">
<meta content="binary format" name="keyword">
<meta content="data interchange format" name="keyword">
<meta content="JSON" name="keyword">
<meta content="8949" name="rfc.number">
<!-- Generator version information:
  xml2rfc 3.5.0
    Python 3.6.10
    appdirs 1.4.4
    ConfigArgParse 1.2.3
    google-i18n-address 2.3.5
    html5lib 1.0.1
    intervaltree 3.0.2
    Jinja2 2.11.2
    kitchen 1.2.6
    lxml 4.4.2
    pycairo 1.19.0
    pycountry 19.8.18
    pyflakes 2.1.1
    PyYAML 5.3.1
    requests 2.22.0
    setuptools 40.6.2
    six 1.14.0
    WeasyPrint 51
-->
<link href="rfc8949.xml" rel="alternate" type="application/rfc+xml">
<link href="#copyright" rel="license">
<style type="text/css">/*

  NOTE: Changes at the bottom of this file overrides some earlier settings.

  Once the style has stabilized and has been adopted as an official RFC style,
  this can be consolidated so that style settings occur only in one place, but
  for now the contents of this file consists first of the initial CSS work as
  provided to the RFC Formatter (xml2rfc) work, followed by itemized and
  commented changes found necssary during the development of the v3
  formatters.

*/

/* fonts */
@import url('https://fonts.googleapis.com/css?family=Noto+Sans'); /* Sans-serif */
@import url('https://fonts.googleapis.com/css?family=Noto+Serif'); /* Serif (print) */
@import url('https://fonts.googleapis.com/css?family=Roboto+Mono'); /* Monospace */

@viewport {
  zoom: 1.0;
  width: extend-to-zoom;
}
@-ms-viewport {
  width: extend-to-zoom;
  zoom: 1.0;
}
/* general and mobile first */
html {
}
body {
  max-width: 90%;
  margin: 1.5em auto;
  color: #222;
  background-color: #fff;
  font-size: 14px;
  font-family: 'Noto Sans', Arial, Helvetica, sans-serif;
  line-height: 1.6;
  scroll-behavior: smooth;
}
.ears {
  display: none;
}

/* headings */
#title, h1, h2, h3, h4, h5, h6 {
  margin: 1em 0 0.5em;
  font-weight: bold;
  line-height: 1.3;
}
#title {
  clear: both;
  border-bottom: 1px solid #ddd;
  margin: 0 0 0.5em 0;
  padding: 1em 0 0.5em;
}
.author {
  padding-bottom: 4px;
}
h1 {
  font-size: 26px;
  margin: 1em 0;
}
h2 {
  font-size: 22px;
  margin-top: -20px;  /* provide offset for in-page anchors */
  padding-top: 33px;
}
h3 {
  font-size: 18px;
  margin-top: -36px;  /* provide offset for in-page anchors */
  padding-top: 42px;
}
h4 {
  font-size: 16px;
  margin-top: -36px;  /* provide offset for in-page anchors */
  padding-top: 42px;
}
h5, h6 {
  font-size: 14px;
}
#n-copyright-notice {
  border-bottom: 1px solid #ddd;
  padding-bottom: 1em;
  margin-bottom: 1em;
}
/* general structure */
p {
  padding: 0;
  margin: 0 0 1em 0;
  text-align: left;
}
div, span {
  position: relative;
}
div {
  margin: 0;
}
.alignRight.art-text {
  background-color: #f9f9f9;
  border: 1px solid #eee;
  border-radius: 3px;
  padding: 1em 1em 0;
  margin-bottom: 1.5em;
}
.alignRight.art-text pre {
  padding: 0;
}
.alignRight {
  margin: 1em 0;
}
.alignRight > *:first-child {
  border: none;
  margin: 0;
  float: right;
  clear: both;
}
.alignRight > *:nth-child(2) {
  clear: both;
  display: block;
  border: none;
}
svg {
  display: block;
}
.alignCenter.art-text {
  background-color: #f9f9f9;
  border: 1px solid #eee;
  border-radius: 3px;
  padding: 1em 1em 0;
  margin-bottom: 1.5em;
}
.alignCenter.art-text pre {
  padding: 0;
}
.alignCenter {
  margin: 1em 0;
}
.alignCenter > *:first-child {
  border: none;
  /* this isn't optimal, but it's an existence proof.  PrinceXML doesn't
     support flexbox yet.
  */
  display: table;
  margin: 0 auto;
}

/* lists */
ol, ul {
  padding: 0;
  margin: 0 0 1em 2em;
}
ol ol, ul ul, ol ul, ul ol {
  margin-left: 1em;
}
li {
  margin: 0 0 0.25em 0;
}
.ulCompact li {
  margin: 0;
}
ul.empty, .ulEmpty {
  list-style-type: none;
}
ul.empty li, .ulEmpty li {
  margin-top: 0.5em;
}
ul.compact, .ulCompact,
ol.compact, .olCompact {
  line-height: 100%;
  margin: 0 0 0 2em;
}

/* definition lists */
dl {
}
dl > dt {
  float: left;
  margin-right: 1em;
}
/* 
dl.nohang > dt {
  float: none;
}
*/
dl > dd {
  margin-bottom: .8em;
  min-height: 1.3em;
}
dl.compact > dd, .dlCompact > dd {
  margin-bottom: 0em;
}
dl > dd > dl {
  margin-top: 0.5em;
  margin-bottom: 0em;
}

/* links */
a {
  text-decoration: none;
}
a[href] {
  color: #22e; /* Arlen: WCAG 2019 */
}
a[href]:hover {
  background-color: #f2f2f2;
}
figcaption a[href],
a[href].selfRef {
  color: #222;
}
/* XXX probably not this:
a.selfRef:hover {
  background-color: transparent;
  cursor: default;
} */

/* Figures */
tt, code, pre, code {
  background-color: #f9f9f9;
  font-family: 'Roboto Mono', monospace;
}
pre {
  border: 1px solid #eee;
  margin: 0;
  padding: 1em;
}
img {
  max-width: 100%;
}
figure {
  margin: 0;
}
figure blockquote {
  margin: 0.8em 0.4em 0.4em;
}
figcaption {
  font-style: italic;
  margin: 0 0 1em 0;
}
@media screen {
  pre {
    overflow-x: auto;
    max-width: 100%;
    max-width: calc(100% - 22px);
  }
}

/* aside, blockquote */
aside, blockquote {
  margin-left: 0;
  padding: 1.2em 2em;
}
blockquote {
  background-color: #f9f9f9;
  color: #111; /* Arlen: WCAG 2019 */
  border: 1px solid #ddd;
  border-radius: 3px;
  margin: 1em 0;
}
cite {
  display: block;
  text-align: right;
  font-style: italic;
}

/* tables */
table {
  width: 100%;
  margin: 0 0 1em;
  border-collapse: collapse;
  border: 1px solid #eee;
}
th, td {
  text-align: left;
  vertical-align: top;
  padding: 0.5em 0.75em;
}
th {
  text-align: left;
  background-color: #e9e9e9;
}
tr:nth-child(2n+1) > td {
  background-color: #f5f5f5;
}
table caption {
  font-style: italic;
  margin: 0;
  padding: 0;
  text-align: left;
}
table p {
  /* XXX to avoid bottom margin on table row signifiers. If paragraphs should
     be allowed within tables more generally, it would be far better to select on a class. */
  margin: 0;
}

/* pilcrow */
a.pilcrow {
  color: #666; /* Arlen: AHDJ 2019 */
  text-decoration: none;
  visibility: hidden;
  user-select: none;
  -ms-user-select: none;
  -o-user-select:none;
  -moz-user-select: none;
  -khtml-user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
@media screen {
  aside:hover > a.pilcrow,
  p:hover > a.pilcrow,
  blockquote:hover > a.pilcrow,
  div:hover > a.pilcrow,
  li:hover > a.pilcrow,
  pre:hover > a.pilcrow {
    visibility: visible;
  }
  a.pilcrow:hover {
    background-color: transparent;
  }
}

/* misc */
hr {
  border: 0;
  border-top: 1px solid #eee;
}
.bcp14 {
  font-variant: small-caps;
}

.role {
  font-variant: all-small-caps;
}

/* info block */
#identifiers {
  margin: 0;
  font-size: 0.9em;
}
#identifiers dt {
  width: 3em;
  clear: left;
}
#identifiers dd {
  float: left;
  margin-bottom: 0;
}
#identifiers .authors .author {
  display: inline-block;
  margin-right: 1.5em;
}
#identifiers .authors .org {
  font-style: italic;
}

/* The prepared/rendered info at the very bottom of the page */
.docInfo {
  color: #666; /* Arlen: WCAG 2019 */
  font-size: 0.9em;
  font-style: italic;
  margin-top: 2em;
}
.docInfo .prepared {
  float: left;
}
.docInfo .prepared {
  float: right;
}

/* table of contents */
#toc  {
  padding: 0.75em 0 2em 0;
  margin-bottom: 1em;
}
nav.toc ul {
  margin: 0 0.5em 0 0;
  padding: 0;
  list-style: none;
}
nav.toc li {
  line-height: 1.3em;
  margin: 0.75em 0;
  padding-left: 1.2em;
  text-indent: -1.2em;
}
/* references */
.references dt {
  text-align: right;
  font-weight: bold;
  min-width: 7em;
}
.references dd {
  margin-left: 8em;
  overflow: auto;
}

.refInstance {
  margin-bottom: 1.25em;
}

.references .ascii {
  margin-bottom: 0.25em;
}

/* index */
.index ul {
  margin: 0 0 0 1em;
  padding: 0;
  list-style: none;
}
.index ul ul {
  margin: 0;
}
.index li {
  margin: 0;
  text-indent: -2em;
  padding-left: 2em;
  padding-bottom: 5px;
}
.indexIndex {
  margin: 0.5em 0 1em;
}
.index a {
  font-weight: 700;
}
/* make the index two-column on all but the smallest screens */
@media (min-width: 600px) {
  .index ul {
    -moz-column-count: 2;
    -moz-column-gap: 20px;
  }
  .index ul ul {
    -moz-column-count: 1;
    -moz-column-gap: 0;
  }
}

/* authors */
address.vcard {
  font-style: normal;
  margin: 1em 0;
}

address.vcard .nameRole {
  font-weight: 700;
  margin-left: 0;
}
address.vcard .label {
  font-family: "Noto Sans",Arial,Helvetica,sans-serif;
  margin: 0.5em 0;
}
address.vcard .type {
  display: none;
}
.alternative-contact {
  margin: 1.5em 0 1em;
}
hr.addr {
  border-top: 1px dashed;
  margin: 0;
  color: #ddd;
  max-width: calc(100% - 16px);
}

/* temporary notes */
.rfcEditorRemove::before {
  position: absolute;
  top: 0.2em;
  right: 0.2em;
  padding: 0.2em;
  content: "The RFC Editor will remove this note";
  color: #9e2a00; /* Arlen: WCAG 2019 */
  background-color: #ffd; /* Arlen: WCAG 2019 */
}
.rfcEditorRemove {
  position: relative;
  padding-top: 1.8em;
  background-color: #ffd; /* Arlen: WCAG 2019 */
  border-radius: 3px;
}
.cref {
  background-color: #ffd; /* Arlen: WCAG 2019 */
  padding: 2px 4px;
}
.crefSource {
  font-style: italic;
}
/* alternative layout for smaller screens */
@media screen and (max-width: 1023px) {
  body {
    padding-top: 2em;
  }
  #title {
    padding: 1em 0;
  }
  h1 {
    font-size: 24px;
  }
  h2 {
    font-size: 20px;
    margin-top: -18px;  /* provide offset for in-page anchors */
    padding-top: 38px;
  }
  #identifiers dd {
    max-width: 60%;
  }
  #toc {
    position: fixed;
    z-index: 2;
    top: 0;
    right: 0;
    padding: 0;
    margin: 0;
    background-color: inherit;
    border-bottom: 1px solid #ccc;
  }
  #toc h2 {
    margin: -1px 0 0 0;
    padding: 4px 0 4px 6px;
    padding-right: 1em;
    min-width: 190px;
    font-size: 1.1em;
    text-align: right;
    background-color: #444;
    color: white;
    cursor: pointer;
  }
  #toc h2::before { /* css hamburger */
    float: right;
    position: relative;
    width: 1em;
    height: 1px;
    left: -164px;
    margin: 6px 0 0 0;
    background: white none repeat scroll 0 0;
    box-shadow: 0 4px 0 0 white, 0 8px 0 0 white;
    content: "";
  }
  #toc nav {
    display: none;
    padding: 0.5em 1em 1em;
    overflow: auto;
    height: calc(100vh - 48px);
    border-left: 1px solid #ddd;
  }
}

/* alternative layout for wide screens */
@media screen and (min-width: 1024px) {
  body {
    max-width: 724px;
    margin: 42px auto;
    padding-left: 1.5em;
    padding-right: 29em;
  }
  #toc {
    position: fixed;
    top: 42px;
    right: 42px;
    width: 25%;
    margin: 0;
    padding: 0 1em;
    z-index: 1;
  }
  #toc h2 {
    border-top: none;
    border-bottom: 1px solid #ddd;
    font-size: 1em;
    font-weight: normal;
    margin: 0;
    padding: 0.25em 1em 1em 0;
  }
  #toc nav {
    display: block;
    height: calc(90vh - 84px);
    bottom: 0;
    padding: 0.5em 0 0;
    overflow: auto;
  }
  img { /* future proofing */
    max-width: 100%;
    height: auto;
  }
}

/* pagination */
@media print {
  body {

    width: 100%;
  }
  p {
    orphans: 3;
    widows: 3;
  }
  #n-copyright-notice {
    border-bottom: none;
  }
  #toc, #n-introduction {
    page-break-before: always;
  }
  #toc {
    border-top: none;
    padding-top: 0;
  }
  figure, pre {
    page-break-inside: avoid;
  }
  figure {
    overflow: scroll;
  }
  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
  }
  h2+*, h3+*, h4+*, h5+*, h6+* {
    page-break-before: avoid;
  }
  pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 10pt;
  }
  table {
    border: 1px solid #ddd;
  }
  td {
    border-top: 1px solid #ddd;
  }
}

/* This is commented out here, as the string-set: doesn't
   pass W3C validation currently */
/*
.ears thead .left {
  string-set: ears-top-left content();
}

.ears thead .center {
  string-set: ears-top-center content();
}

.ears thead .right {
  string-set: ears-top-right content();
}

.ears tfoot .left {
  string-set: ears-bottom-left content();
}

.ears tfoot .center {
  string-set: ears-bottom-center content();
}

.ears tfoot .right {
  string-set: ears-bottom-right content();
}
*/

@page :first {
  padding-top: 0;
  @top-left {
    content: normal;
    border: none;
  }
  @top-center {
    content: normal;
    border: none;
  }
  @top-right {
    content: normal;
    border: none;
  }
}

@page {
  size: A4;
  margin-bottom: 45mm;
  padding-top: 20px;
  /* The follwing is commented out here, but set appropriately by in code, as
     the content depends on the document */
  /*
  @top-left {
    content: 'Internet-Draft';
    vertical-align: bottom;
    border-bottom: solid 1px #ccc;
  }
  @top-left {
    content: string(ears-top-left);
    vertical-align: bottom;
    border-bottom: solid 1px #ccc;
  }
  @top-center {
    content: string(ears-top-center);
    vertical-align: bottom;
    border-bottom: solid 1px #ccc;
  }
  @top-right {
    content: string(ears-top-right);
    vertical-align: bottom;
    border-bottom: solid 1px #ccc;
  }
  @bottom-left {
    content: string(ears-bottom-left);
    vertical-align: top;
    border-top: solid 1px #ccc;
  }
  @bottom-center {
    content: string(ears-bottom-center);
    vertical-align: top;
    border-top: solid 1px #ccc;
  }
  @bottom-right {
      content: '[Page ' counter(page) ']';
      vertical-align: top;
      border-top: solid 1px #ccc;
  }
  */

}

/* Changes introduced to fix issues found during implementation */
/* Make sure links are clickable even if overlapped by following H* */
a {
  z-index: 2;
}
/* Separate body from document info even without intervening H1 */
section {
  clear: both;
}


/* Top align author divs, to avoid names without organization dropping level with org names */
.author {
  vertical-align: top;
}

/* Leave room in document info to show Internet-Draft on one line */
#identifiers dt {
  width: 8em;
}

/* Don't waste quite as much whitespace between label and value in doc info */
#identifiers dd {
  margin-left: 1em;
}

/* Give floating toc a background color (needed when it's a div inside section */
#toc {
  background-color: white;
}

/* Make the collapsed ToC header render white on gray also when it's a link */
@media screen and (max-width: 1023px) {
  #toc h2 a,
  #toc h2 a:link,
  #toc h2 a:focus,
  #toc h2 a:hover,
  #toc a.toplink,
  #toc a.toplink:hover {
    color: white;
    background-color: #444;
    text-decoration: none;
  }
}

/* Give the bottom of the ToC some whitespace */
@media screen and (min-width: 1024px) {
  #toc {
    padding: 0 0 1em 1em;
  }
}

/* Style section numbers with more space between number and title */
.section-number {
  padding-right: 0.5em;
}

/* prevent monospace from becoming overly large */
tt, code, pre, code {
  font-size: 95%;
}

/* Fix the height/width aspect for ascii art*/
pre.sourcecode,
.art-text pre {
  line-height: 1.12;
}


/* Add styling for a link in the ToC that points to the top of the document */
a.toplink {
  float: right;
  margin-right: 0.5em;
}

/* Fix the dl styling to match the RFC 7992 attributes */
dl > dt,
dl.dlParallel > dt {
  float: left;
  margin-right: 1em;
}
dl.dlNewline > dt {
  float: none;
}

/* Provide styling for table cell text alignment */
table td.text-left,
table th.text-left {
  text-align: left;
}
table td.text-center,
table th.text-center {
  text-align: center;
}
table td.text-right,
table th.text-right {
  text-align: right;
}

/* Make the alternative author contact informatio look less like just another
   author, and group it closer with the primary author contact information */
.alternative-contact {
  margin: 0.5em 0 0.25em 0;
}
address .non-ascii {
  margin: 0 0 0 2em;
}

/* With it being possible to set tables with alignment
  left, center, and right, { width: 100%; } does not make sense */
table {
  width: auto;
}

/* Avoid reference text that sits in a block with very wide left margin,
   because of a long floating dt label.*/
.references dd {
  overflow: visible;
}

/* Control caption placement */
caption {
  caption-side: bottom;
}

/* Limit the width of the author address vcard, so names in right-to-left
   script don't end up on the other side of the page. */

address.vcard {
  max-width: 30em;
  margin-right: auto;
}

/* For address alignment dependent on LTR or RTL scripts */
address div.left {
  text-align: left;
}
address div.right {
  text-align: right;
}

/* Provide table alignment support.  We can't use the alignX classes above
   since they do unwanted things with caption and other styling. */
table.right {
 margin-left: auto;
 margin-right: 0;
}
table.center {
 margin-left: auto;
 margin-right: auto;
}
table.left {
 margin-left: 0;
 margin-right: auto;
}

/* Give the table caption label the same styling as the figcaption */
caption a[href] {
  color: #222;
}

@media print {
  .toplink {
    display: none;
  }

  /* avoid overwriting the top border line with the ToC header */
  #toc {
    padding-top: 1px;
  }

  /* Avoid page breaks inside dl and author address entries */
  .vcard {
    page-break-inside: avoid;
  }

}
/* Tweak the bcp14 keyword presentation */
.bcp14 {
  font-variant: small-caps;
  font-weight: bold;
  font-size: 0.9em;
}
/* Tweak the invisible space above H* in order not to overlay links in text above */
 h2 {
  margin-top: -18px;  /* provide offset for in-page anchors */
  padding-top: 31px;
 }
 h3 {
  margin-top: -18px;  /* provide offset for in-page anchors */
  padding-top: 24px;
 }
 h4 {
  margin-top: -18px;  /* provide offset for in-page anchors */
  padding-top: 24px;
 }
/* Float artwork pilcrow to the right */
@media screen {
  .artwork a.pilcrow {
    display: block;
    line-height: 0.7;
    margin-top: 0.15em;
  }
}
/* Make pilcrows on dd visible */
@media screen {
  dd:hover > a.pilcrow {
    visibility: visible;
  }
}
/* Make the placement of figcaption match that of a table's caption
   by removing the figure's added bottom margin */
.alignLeft.art-text,
.alignCenter.art-text,
.alignRight.art-text {
   margin-bottom: 0;
}
.alignLeft,
.alignCenter,
.alignRight {
  margin: 1em 0 0 0;
}
/* In print, the pilcrow won't show on hover, so prevent it from taking up space,
   possibly even requiring a new line */
@media print {
  a.pilcrow {
    display: none;
  }
}
/* Styling for the external metadata */
div#external-metadata {
  background-color: #eee;
  padding: 0.5em;
  margin-bottom: 0.5em;
  display: none;
}
div#internal-metadata {
  padding: 0.5em;                       /* to match the external-metadata padding */
}
/* Styling for title RFC Number */
h1#rfcnum {
  clear: both;
  margin: 0 0 -1em;
  padding: 1em 0 0 0;
}
/* Make .olPercent look the same as <ol><li> */
dl.olPercent > dd {
  margin-bottom: 0.25em;
  min-height: initial;
}
/* Give aside some styling to set it apart */
aside {
  border-left: 1px solid #ddd;
  margin: 1em 0 1em 2em;
  padding: 0.2em 2em;
}
aside > dl,
aside > ol,
aside > ul,
aside > table,
aside > p {
  margin-bottom: 0.5em;
}
/* Additional page break settings */
@media print {
  figcaption, table caption {
    page-break-before: avoid;
  }
}
/* Font size adjustments for print */
@media print {
  body  { font-size: 10pt;      line-height: normal; max-width: 96%; }
  h1    { font-size: 1.72em;    padding-top: 1.5em; } /* 1*1.2*1.2*1.2 */
  h2    { font-size: 1.44em;    padding-top: 1.5em; } /* 1*1.2*1.2 */
  h3    { font-size: 1.2em;     padding-top: 1.5em; } /* 1*1.2 */
  h4    { font-size: 1em;       padding-top: 1.5em; }
  h5, h6 { font-size: 1em;      margin: initial; padding: 0.5em 0 0.3em; }
}
/* Sourcecode margin in print, when there's no pilcrow */
@media print {
  .artwork,
  .sourcecode {
    margin-bottom: 1em;
  }
}
/* Avoid narrow tables forcing too narrow table captions, which may render badly */
table {
  min-width: 20em;
}
/* ol type a */
ol.type-a { list-style-type: lower-alpha; }
ol.type-A { list-style-type: upper-alpha; }
ol.type-i { list-style-type: lower-roman; }
ol.type-I { list-style-type: lower-roman; }
/* Apply the print table and row borders in general, on request from the RPC,
and increase the contrast between border and odd row background sligthtly */
table {
  border: 1px solid #ddd;
}
td {
  border-top: 1px solid #ddd;
}
tr:nth-child(2n+1) > td {
  background-color: #f8f8f8;
}
/* Use style rules to govern display of the TOC. */
@media screen and (max-width: 1023px) {
  #toc nav { display: none; }
  #toc.active nav { display: block; }
}
/* Add support for keepWithNext */
.keepWithNext {
  break-after: avoid-page;
  break-after: avoid-page;
}
/* Add support for keepWithPrevious */
.keepWithPrevious {
  break-before: avoid-page;
}
/* Change the approach to avoiding breaks inside artwork etc. */
figure, pre, table, .artwork, .sourcecode  {
  break-before: avoid-page;
  break-after: auto;
}
/* Avoid breaks between <dt> and <dd> */
dl {
  break-before: auto;
  break-inside: auto;
}
dt {
  break-before: auto;
  break-after: avoid-page;
}
dd {
  break-before: avoid-page;
  break-after: auto;
  orphans: 3;
  widows: 3
}
span.break, dd.break {
  margin-bottom: 0;
  min-height: 0;
  break-before: auto;
  break-inside: auto;
  break-after: auto;
}
/* Undo break-before ToC */
@media print {
  #toc {
    break-before: auto;
  }
}
/* Text in compact lists should not get extra bottim margin space,
   since that would makes the list not compact */
ul.compact p, .ulCompact p,
ol.compact p, .olCompact p {
 margin: 0;
}
/* But the list as a whole needs the extra space at the end */
section ul.compact,
section .ulCompact,
section ol.compact,
section .olCompact {
  margin-bottom: 1em;                    /* same as p not within ul.compact etc. */
}
/* The tt and code background above interferes with for instance table cell
   backgrounds.  Changed to something a bit more selective. */
tt, code {
  background-color: transparent;
}
p tt, p code, li tt, li code {
  background-color: #f8f8f8;
}
/* Tweak the pre margin -- 0px doesn't come out well */
pre {
   margin-top: 0.5px;
}
/* Tweak the comact list text */
ul.compact, .ulCompact,
ol.compact, .olCompact,
dl.compact, .dlCompact {
  line-height: normal;
}
/* Don't add top margin for nested lists */
li > ul, li > ol, li > dl,
dd > ul, dd > ol, dd > dl,
dl > dd > dl {
  margin-top: initial;
}
/* Elements that should not be rendered on the same line as a <dt> */
/* This should match the element list in writer.text.TextWriter.render_dl() */
dd > div.artwork:first-child,
dd > aside:first-child,
dd > figure:first-child,
dd > ol:first-child,
dd > div:first-child > pre.sourcecode,
dd > table:first-child,
dd > ul:first-child {
  clear: left;
}
/* fix for weird browser behaviour when <dd/> is empty */
dt+dd:empty::before{
  content: "\00a0";
}
</style>
<link href="rfc-local.css" rel="stylesheet" type="text/css">
<link href="https://dx.doi.org/10.17487/rfc8949" rel="alternate">
  <link href="urn:issn:2070-1721" rel="alternate">
  <link href="https://datatracker.ietf.org/doc/draft-ietf-cbor-7049bis-16" rel="prev">
  </head>
<body>
<script src="https://www.rfc-editor.org/js/metadata.min.js"></script>
<table class="ears">
<thead><tr>
<td class="left">RFC 8949</td>
<td class="center">CBOR</td>
<td class="right">December 2020</td>
</tr></thead>
<tfoot><tr>
<td class="left">Bormann &amp; Hoffman</td>
<td class="center">Standards Track</td>
<td class="right">[Page]</td>
</tr></tfoot>
</table>
<div id="external-metadata" class="document-information"></div>
<div id="internal-metadata" class="document-information">
<dl id="identifiers">
<dt class="label-stream">Stream:</dt>
<dd class="stream">Internet Engineering Task Force (IETF)</dd>
<dt class="label-rfc">RFC:</dt>
<dd class="rfc"><a href="https://www.rfc-editor.org/rfc/rfc8949" class="eref">8949</a></dd>
<dt class="label-std">STD:</dt>
<dd class="std">94</dd>
<dt class="label-obsoletes">Obsoletes:</dt>
<dd class="obsoletes">
<a href="https://www.rfc-editor.org/rfc/rfc7049" class="eref">7049</a> </dd>
<dt class="label-category">Category:</dt>
<dd class="category">Standards Track</dd>
<dt class="label-published">Published:</dt>
<dd class="published">
<time datetime="2020-12" class="published">December 2020</time>
    </dd>
<dt class="label-issn">ISSN:</dt>
<dd class="issn">2070-1721</dd>
<dt class="label-authors">Authors:</dt>
<dd class="authors">
<div class="author">
      <div class="author-name">C. Bormann</div>
<div class="org">Universität Bremen TZI</div>
</div>
<div class="author">
      <div class="author-name">P. Hoffman</div>
<div class="org">ICANN</div>
</div>
</dd>
</dl>
</div>
<h1 id="rfcnum">RFC 8949</h1>
<h1 id="title">Concise Binary Object Representation (CBOR)</h1>
<section id="section-abstract">
      <h2 id="abstract"><a href="#abstract" class="selfRef">Abstract</a></h2>
<p id="section-abstract-1">The Concise Binary Object Representation (CBOR) is a data format whose design
goals include the
possibility of extremely small code size, fairly small message size, and
extensibility without the
need for version negotiation. These design goals make it different from earlier
binary
serializations such as ASN.1 and MessagePack.<a href="#section-abstract-1" class="pilcrow">¶</a></p>
<p id="section-abstract-2"> This document obsoletes RFC 7049, providing editorial improvements, new 
   details, and errata fixes while keeping full compatibility with 
   the interchange format of RFC 7049.  It does not create a new version
   of the format.<a href="#section-abstract-2" class="pilcrow">¶</a></p>
</section>
<div id="status-of-memo">
<section id="section-boilerplate.1">
        <h2 id="name-status-of-this-memo">
<a href="#name-status-of-this-memo" class="section-name selfRef">Status of This Memo</a>
        </h2>
<p id="section-boilerplate.1-1">
            This is an Internet Standards Track document.<a href="#section-boilerplate.1-1" class="pilcrow">¶</a></p>
<p id="section-boilerplate.1-2">
            This document is a product of the Internet Engineering Task Force
            (IETF).  It represents the consensus of the IETF community.  It has
            received public review and has been approved for publication by
            the Internet Engineering Steering Group (IESG).  Further
            information on Internet Standards is available in Section 2 of 
            RFC 7841.<a href="#section-boilerplate.1-2" class="pilcrow">¶</a></p>
<p id="section-boilerplate.1-3">
            Information about the current status of this document, any
            errata, and how to provide feedback on it may be obtained at
            <span><a href="https://www.rfc-editor.org/info/rfc8949">https://www.rfc-editor.org/info/rfc8949</a></span>.<a href="#section-boilerplate.1-3" class="pilcrow">¶</a></p>
</section>
</div>
<div id="copyright">
<section id="section-boilerplate.2">
        <h2 id="name-copyright-notice">
<a href="#name-copyright-notice" class="section-name selfRef">Copyright Notice</a>
        </h2>
<p id="section-boilerplate.2-1">
            Copyright (c) 2020 IETF Trust and the persons identified as the
            document authors. All rights reserved.<a href="#section-boilerplate.2-1" class="pilcrow">¶</a></p>
<p id="section-boilerplate.2-2">
            This document is subject to BCP 78 and the IETF Trust's Legal
            Provisions Relating to IETF Documents
            (<span><a href="https://trustee.ietf.org/license-info">https://trustee.ietf.org/license-info</a></span>) in effect on the date of
            publication of this document. Please review these documents
            carefully, as they describe your rights and restrictions with
            respect to this document. Code Components extracted from this
            document must include Simplified BSD License text as described in
            Section 4.e of the Trust Legal Provisions and are provided without
            warranty as described in the Simplified BSD License.<a href="#section-boilerplate.2-2" class="pilcrow">¶</a></p>
</section>
</div>
<div id="toc">
<section id="section-toc.1">
        <a href="#" onclick="scroll(0,0)" class="toplink">▲</a><h2 id="name-table-of-contents">
<a href="#name-table-of-contents" class="section-name selfRef">Table of Contents</a>
        </h2>
<nav class="toc"><ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.1">
            <p id="section-toc.1-1.1.1" class="keepWithNext"><a href="#section-1" class="xref">1</a>.  <a href="#name-introduction" class="xref">Introduction</a><a href="#section-toc.1-1.1.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.1.2.1">
                <p id="section-toc.1-1.1.2.1.1" class="keepWithNext"><a href="#section-1.1" class="xref">1.1</a>.  <a href="#name-objectives" class="xref">Objectives</a><a href="#section-toc.1-1.1.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.1.2.2">
                <p id="section-toc.1-1.1.2.2.1" class="keepWithNext"><a href="#section-1.2" class="xref">1.2</a>.  <a href="#name-terminology" class="xref">Terminology</a><a href="#section-toc.1-1.1.2.2.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.2">
            <p id="section-toc.1-1.2.1"><a href="#section-2" class="xref">2</a>.  <a href="#name-cbor-data-models" class="xref">CBOR Data Models</a><a href="#section-toc.1-1.2.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.2.2.1">
                <p id="section-toc.1-1.2.2.1.1"><a href="#section-2.1" class="xref">2.1</a>.  <a href="#name-extended-generic-data-model" class="xref">Extended Generic Data Models</a><a href="#section-toc.1-1.2.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.2.2.2">
                <p id="section-toc.1-1.2.2.2.1"><a href="#section-2.2" class="xref">2.2</a>.  <a href="#name-specific-data-models" class="xref">Specific Data Models</a><a href="#section-toc.1-1.2.2.2.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.3">
            <p id="section-toc.1-1.3.1"><a href="#section-3" class="xref">3</a>.  <a href="#name-specification-of-the-cbor-e" class="xref">Specification of the CBOR Encoding</a><a href="#section-toc.1-1.3.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.3.2.1">
                <p id="section-toc.1-1.3.2.1.1"><a href="#section-3.1" class="xref">3.1</a>.  <a href="#name-major-types" class="xref">Major Types</a><a href="#section-toc.1-1.3.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.2">
                <p id="section-toc.1-1.3.2.2.1"><a href="#section-3.2" class="xref">3.2</a>.  <a href="#name-indefinite-lengths-for-some" class="xref">Indefinite Lengths for Some Major Types</a><a href="#section-toc.1-1.3.2.2.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.3.2.2.2.1">
                    <p id="section-toc.1-1.3.2.2.2.1.1"><a href="#section-3.2.1" class="xref">3.2.1</a>.  <a href="#name-the-break-stop-code" class="xref">The "break" Stop Code</a><a href="#section-toc.1-1.3.2.2.2.1.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.2.2.2">
                    <p id="section-toc.1-1.3.2.2.2.2.1"><a href="#section-3.2.2" class="xref">3.2.2</a>.  <a href="#name-indefinite-length-arrays-an" class="xref">Indefinite-Length Arrays and Maps</a><a href="#section-toc.1-1.3.2.2.2.2.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.2.2.3">
                    <p id="section-toc.1-1.3.2.2.2.3.1"><a href="#section-3.2.3" class="xref">3.2.3</a>.  <a href="#name-indefinite-length-byte-stri" class="xref">Indefinite-Length Byte Strings and Text Strings</a><a href="#section-toc.1-1.3.2.2.2.3.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.2.2.4">
                    <p id="section-toc.1-1.3.2.2.2.4.1"><a href="#section-3.2.4" class="xref">3.2.4</a>.  <a href="#name-summary-of-indefinite-lengt" class="xref">Summary of Indefinite-Length Use of Major Types</a><a href="#section-toc.1-1.3.2.2.2.4.1" class="pilcrow">¶</a></p>
</li>
                </ul>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.3">
                <p id="section-toc.1-1.3.2.3.1"><a href="#section-3.3" class="xref">3.3</a>.  <a href="#name-floating-point-numbers-and-" class="xref">Floating-Point Numbers and Values with No Content</a><a href="#section-toc.1-1.3.2.3.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4">
                <p id="section-toc.1-1.3.2.4.1"><a href="#section-3.4" class="xref">3.4</a>.  <a href="#name-tagging-of-items" class="xref">Tagging of Items</a><a href="#section-toc.1-1.3.2.4.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4.2.1">
                    <p id="section-toc.1-1.3.2.4.2.1.1"><a href="#section-3.4.1" class="xref">3.4.1</a>.  <a href="#name-standard-date-time-string" class="xref">Standard Date/Time String</a><a href="#section-toc.1-1.3.2.4.2.1.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4.2.2">
                    <p id="section-toc.1-1.3.2.4.2.2.1"><a href="#section-3.4.2" class="xref">3.4.2</a>.  <a href="#name-epoch-based-date-time" class="xref">Epoch-Based Date/Time</a><a href="#section-toc.1-1.3.2.4.2.2.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4.2.3">
                    <p id="section-toc.1-1.3.2.4.2.3.1"><a href="#section-3.4.3" class="xref">3.4.3</a>.  <a href="#name-bignums" class="xref">Bignums</a><a href="#section-toc.1-1.3.2.4.2.3.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4.2.4">
                    <p id="section-toc.1-1.3.2.4.2.4.1"><a href="#section-3.4.4" class="xref">3.4.4</a>.  <a href="#name-decimal-fractions-and-bigfl" class="xref">Decimal Fractions and Bigfloats</a><a href="#section-toc.1-1.3.2.4.2.4.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4.2.5">
                    <p id="section-toc.1-1.3.2.4.2.5.1"><a href="#section-3.4.5" class="xref">3.4.5</a>.  <a href="#name-content-hints" class="xref">Content Hints</a><a href="#section-toc.1-1.3.2.4.2.5.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4.2.5.2.1">
                        <p id="section-toc.1-1.3.2.4.2.5.2.1.1"><a href="#section-3.4.5.1" class="xref">3.4.5.1</a>.  <a href="#name-encoded-cbor-data-item" class="xref">Encoded CBOR Data Item</a><a href="#section-toc.1-1.3.2.4.2.5.2.1.1" class="pilcrow">¶</a></p>
</li>
                      <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4.2.5.2.2">
                        <p id="section-toc.1-1.3.2.4.2.5.2.2.1"><a href="#section-3.4.5.2" class="xref">3.4.5.2</a>.  <a href="#name-expected-later-encoding-for" class="xref">Expected Later Encoding for CBOR-to-JSON Converters</a><a href="#section-toc.1-1.3.2.4.2.5.2.2.1" class="pilcrow">¶</a></p>
</li>
                      <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4.2.5.2.3">
                        <p id="section-toc.1-1.3.2.4.2.5.2.3.1"><a href="#section-3.4.5.3" class="xref">3.4.5.3</a>.  <a href="#name-encoded-text" class="xref">Encoded Text</a><a href="#section-toc.1-1.3.2.4.2.5.2.3.1" class="pilcrow">¶</a></p>
</li>
                    </ul>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.3.2.4.2.6">
                    <p id="section-toc.1-1.3.2.4.2.6.1"><a href="#section-3.4.6" class="xref">3.4.6</a>.  <a href="#name-self-described-cbor" class="xref">Self-Described CBOR</a><a href="#section-toc.1-1.3.2.4.2.6.1" class="pilcrow">¶</a></p>
</li>
                </ul>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.4">
            <p id="section-toc.1-1.4.1"><a href="#section-4" class="xref">4</a>.  <a href="#name-serialization-consideration" class="xref">Serialization Considerations</a><a href="#section-toc.1-1.4.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.4.2.1">
                <p id="section-toc.1-1.4.2.1.1"><a href="#section-4.1" class="xref">4.1</a>.  <a href="#name-preferred-serialization" class="xref">Preferred Serialization</a><a href="#section-toc.1-1.4.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.4.2.2">
                <p id="section-toc.1-1.4.2.2.1"><a href="#section-4.2" class="xref">4.2</a>.  <a href="#name-deterministically-encoded-c" class="xref">Deterministically Encoded CBOR</a><a href="#section-toc.1-1.4.2.2.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.4.2.2.2.1">
                    <p id="section-toc.1-1.4.2.2.2.1.1"><a href="#section-4.2.1" class="xref">4.2.1</a>.  <a href="#name-core-deterministic-encoding" class="xref">Core Deterministic Encoding Requirements</a><a href="#section-toc.1-1.4.2.2.2.1.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.4.2.2.2.2">
                    <p id="section-toc.1-1.4.2.2.2.2.1"><a href="#section-4.2.2" class="xref">4.2.2</a>.  <a href="#name-additional-deterministic-en" class="xref">Additional Deterministic Encoding Considerations</a><a href="#section-toc.1-1.4.2.2.2.2.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.4.2.2.2.3">
                    <p id="section-toc.1-1.4.2.2.2.3.1"><a href="#section-4.2.3" class="xref">4.2.3</a>.  <a href="#name-length-first-map-key-orderi" class="xref">Length-First Map Key Ordering</a><a href="#section-toc.1-1.4.2.2.2.3.1" class="pilcrow">¶</a></p>
</li>
                </ul>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.5">
            <p id="section-toc.1-1.5.1"><a href="#section-5" class="xref">5</a>.  <a href="#name-creating-cbor-based-protoco" class="xref">Creating CBOR-Based Protocols</a><a href="#section-toc.1-1.5.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.5.2.1">
                <p id="section-toc.1-1.5.2.1.1"><a href="#section-5.1" class="xref">5.1</a>.  <a href="#name-cbor-in-streaming-applicati" class="xref">CBOR in Streaming Applications</a><a href="#section-toc.1-1.5.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.5.2.2">
                <p id="section-toc.1-1.5.2.2.1"><a href="#section-5.2" class="xref">5.2</a>.  <a href="#name-generic-encoders-and-decode" class="xref">Generic Encoders and Decoders</a><a href="#section-toc.1-1.5.2.2.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.5.2.3">
                <p id="section-toc.1-1.5.2.3.1"><a href="#section-5.3" class="xref">5.3</a>.  <a href="#name-validity-of-items" class="xref">Validity of Items</a><a href="#section-toc.1-1.5.2.3.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.5.2.3.2.1">
                    <p id="section-toc.1-1.5.2.3.2.1.1"><a href="#section-5.3.1" class="xref">5.3.1</a>.  <a href="#name-basic-validity" class="xref">Basic validity</a><a href="#section-toc.1-1.5.2.3.2.1.1" class="pilcrow">¶</a></p>
</li>
                  <li class="ulEmpty compact toc" id="section-toc.1-1.5.2.3.2.2">
                    <p id="section-toc.1-1.5.2.3.2.2.1"><a href="#section-5.3.2" class="xref">5.3.2</a>.  <a href="#name-tag-validity" class="xref">Tag validity</a><a href="#section-toc.1-1.5.2.3.2.2.1" class="pilcrow">¶</a></p>
</li>
                </ul>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.5.2.4">
                <p id="section-toc.1-1.5.2.4.1"><a href="#section-5.4" class="xref">5.4</a>.  <a href="#name-validity-and-evolution" class="xref">Validity and Evolution</a><a href="#section-toc.1-1.5.2.4.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.5.2.5">
                <p id="section-toc.1-1.5.2.5.1"><a href="#section-5.5" class="xref">5.5</a>.  <a href="#name-numbers" class="xref">Numbers</a><a href="#section-toc.1-1.5.2.5.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.5.2.6">
                <p id="section-toc.1-1.5.2.6.1"><a href="#section-5.6" class="xref">5.6</a>.  <a href="#name-specifying-keys-for-maps" class="xref">Specifying Keys for Maps</a><a href="#section-toc.1-1.5.2.6.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.5.2.6.2.1">
                    <p id="section-toc.1-1.5.2.6.2.1.1"><a href="#section-5.6.1" class="xref">5.6.1</a>.  <a href="#name-equivalence-of-keys" class="xref">Equivalence of Keys</a><a href="#section-toc.1-1.5.2.6.2.1.1" class="pilcrow">¶</a></p>
</li>
                </ul>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.5.2.7">
                <p id="section-toc.1-1.5.2.7.1"><a href="#section-5.7" class="xref">5.7</a>.  <a href="#name-undefined-values" class="xref">Undefined Values</a><a href="#section-toc.1-1.5.2.7.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.6">
            <p id="section-toc.1-1.6.1"><a href="#section-6" class="xref">6</a>.  <a href="#name-converting-data-between-cbo" class="xref">Converting Data between CBOR and JSON</a><a href="#section-toc.1-1.6.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.6.2.1">
                <p id="section-toc.1-1.6.2.1.1"><a href="#section-6.1" class="xref">6.1</a>.  <a href="#name-converting-from-cbor-to-jso" class="xref">Converting from CBOR to JSON</a><a href="#section-toc.1-1.6.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.6.2.2">
                <p id="section-toc.1-1.6.2.2.1"><a href="#section-6.2" class="xref">6.2</a>.  <a href="#name-converting-from-json-to-cbo" class="xref">Converting from JSON to CBOR</a><a href="#section-toc.1-1.6.2.2.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.7">
            <p id="section-toc.1-1.7.1"><a href="#section-7" class="xref">7</a>.  <a href="#name-future-evolution-of-cbor" class="xref">Future Evolution of CBOR</a><a href="#section-toc.1-1.7.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.7.2.1">
                <p id="section-toc.1-1.7.2.1.1"><a href="#section-7.1" class="xref">7.1</a>.  <a href="#name-extension-points" class="xref">Extension Points</a><a href="#section-toc.1-1.7.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.7.2.2">
                <p id="section-toc.1-1.7.2.2.1"><a href="#section-7.2" class="xref">7.2</a>.  <a href="#name-curating-the-additional-inf" class="xref">Curating the Additional Information Space</a><a href="#section-toc.1-1.7.2.2.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.8">
            <p id="section-toc.1-1.8.1"><a href="#section-8" class="xref">8</a>.  <a href="#name-diagnostic-notation" class="xref">Diagnostic Notation</a><a href="#section-toc.1-1.8.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.8.2.1">
                <p id="section-toc.1-1.8.2.1.1"><a href="#section-8.1" class="xref">8.1</a>.  <a href="#name-encoding-indicators" class="xref">Encoding Indicators</a><a href="#section-toc.1-1.8.2.1.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.9">
            <p id="section-toc.1-1.9.1"><a href="#section-9" class="xref">9</a>.  <a href="#name-iana-considerations" class="xref">IANA Considerations</a><a href="#section-toc.1-1.9.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.9.2.1">
                <p id="section-toc.1-1.9.2.1.1"><a href="#section-9.1" class="xref">9.1</a>.  <a href="#name-cbor-simple-values-registry" class="xref">CBOR Simple Values Registry</a><a href="#section-toc.1-1.9.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.9.2.2">
                <p id="section-toc.1-1.9.2.2.1"><a href="#section-9.2" class="xref">9.2</a>.  <a href="#name-cbor-tags-registry" class="xref">CBOR Tags Registry</a><a href="#section-toc.1-1.9.2.2.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.9.2.3">
                <p id="section-toc.1-1.9.2.3.1"><a href="#section-9.3" class="xref">9.3</a>.  <a href="#name-media-types-registry" class="xref">Media Types Registry</a><a href="#section-toc.1-1.9.2.3.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.9.2.4">
                <p id="section-toc.1-1.9.2.4.1"><a href="#section-9.4" class="xref">9.4</a>.  <a href="#name-coap-content-format-registr" class="xref">CoAP Content-Format Registry</a><a href="#section-toc.1-1.9.2.4.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.9.2.5">
                <p id="section-toc.1-1.9.2.5.1"><a href="#section-9.5" class="xref">9.5</a>.  <a href="#name-structured-syntax-suffix-re" class="xref">Structured Syntax Suffix Registry</a><a href="#section-toc.1-1.9.2.5.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.10">
            <p id="section-toc.1-1.10.1"><a href="#section-10" class="xref">10</a>. <a href="#name-security-considerations" class="xref">Security Considerations</a><a href="#section-toc.1-1.10.1" class="pilcrow">¶</a></p>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.11">
            <p id="section-toc.1-1.11.1"><a href="#section-11" class="xref">11</a>. <a href="#name-references" class="xref">References</a><a href="#section-toc.1-1.11.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.11.2.1">
                <p id="section-toc.1-1.11.2.1.1"><a href="#section-11.1" class="xref">11.1</a>.  <a href="#name-normative-references" class="xref">Normative References</a><a href="#section-toc.1-1.11.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.11.2.2">
                <p id="section-toc.1-1.11.2.2.1"><a href="#section-11.2" class="xref">11.2</a>.  <a href="#name-informative-references" class="xref">Informative References</a><a href="#section-toc.1-1.11.2.2.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.12">
            <p id="section-toc.1-1.12.1"><a href="#section-appendix.a" class="xref">Appendix A</a>.  <a href="#name-examples-of-encoded-cbor-da" class="xref">Examples of Encoded CBOR Data Items</a><a href="#section-toc.1-1.12.1" class="pilcrow">¶</a></p>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.13">
            <p id="section-toc.1-1.13.1"><a href="#section-appendix.b" class="xref">Appendix B</a>.  <a href="#name-jump-table-for-initial-byte" class="xref">Jump Table for Initial Byte</a><a href="#section-toc.1-1.13.1" class="pilcrow">¶</a></p>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.14">
            <p id="section-toc.1-1.14.1"><a href="#section-appendix.c" class="xref">Appendix C</a>.  <a href="#name-pseudocode" class="xref">Pseudocode</a><a href="#section-toc.1-1.14.1" class="pilcrow">¶</a></p>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.15">
            <p id="section-toc.1-1.15.1"><a href="#section-appendix.d" class="xref">Appendix D</a>.  <a href="#name-half-precision" class="xref">Half-Precision</a><a href="#section-toc.1-1.15.1" class="pilcrow">¶</a></p>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.16">
            <p id="section-toc.1-1.16.1"><a href="#section-appendix.e" class="xref">Appendix E</a>.  <a href="#name-comparison-of-other-binary-" class="xref">Comparison of Other Binary Formats to CBOR's Design Objectives</a><a href="#section-toc.1-1.16.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.16.2.1">
                <p id="section-toc.1-1.16.2.1.1"><a href="#section-e.1" class="xref">E.1</a>.  <a href="#name-asn1-der-ber-and-per" class="xref">ASN.1 DER, BER, and PER</a><a href="#section-toc.1-1.16.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.16.2.2">
                <p id="section-toc.1-1.16.2.2.1"><a href="#section-e.2" class="xref">E.2</a>.  <a href="#name-messagepack" class="xref">MessagePack</a><a href="#section-toc.1-1.16.2.2.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.16.2.3">
                <p id="section-toc.1-1.16.2.3.1"><a href="#section-e.3" class="xref">E.3</a>.  <a href="#name-bson" class="xref">BSON</a><a href="#section-toc.1-1.16.2.3.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.16.2.4">
                <p id="section-toc.1-1.16.2.4.1"><a href="#section-e.4" class="xref">E.4</a>.  <a href="#name-msdtp-rfc-713" class="xref">MSDTP: RFC 713</a><a href="#section-toc.1-1.16.2.4.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.16.2.5">
                <p id="section-toc.1-1.16.2.5.1"><a href="#section-e.5" class="xref">E.5</a>.  <a href="#name-conciseness-on-the-wire" class="xref">Conciseness on the Wire</a><a href="#section-toc.1-1.16.2.5.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.17">
            <p id="section-toc.1-1.17.1"><a href="#section-appendix.f" class="xref">Appendix F</a>.  <a href="#name-well-formedness-errors-and-" class="xref">Well-Formedness Errors and Examples</a><a href="#section-toc.1-1.17.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.17.2.1">
                <p id="section-toc.1-1.17.2.1.1"><a href="#section-f.1" class="xref">F.1</a>.  <a href="#name-examples-of-cbor-data-items" class="xref">Examples of CBOR Data Items That Are Not Well-Formed</a><a href="#section-toc.1-1.17.2.1.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.18">
            <p id="section-toc.1-1.18.1"><a href="#section-appendix.g" class="xref">Appendix G</a>.  <a href="#name-changes-from-rfc-7049" class="xref">Changes from RFC 7049</a><a href="#section-toc.1-1.18.1" class="pilcrow">¶</a></p>
<ul class="ulEmpty compact toc">
<li class="ulEmpty compact toc" id="section-toc.1-1.18.2.1">
                <p id="section-toc.1-1.18.2.1.1"><a href="#section-g.1" class="xref">G.1</a>.  <a href="#name-errata-processing-and-cleri" class="xref">Errata Processing and Clerical Changes</a><a href="#section-toc.1-1.18.2.1.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.18.2.2">
                <p id="section-toc.1-1.18.2.2.1"><a href="#section-g.2" class="xref">G.2</a>.  <a href="#name-changes-in-iana-considerati" class="xref">Changes in IANA Considerations</a><a href="#section-toc.1-1.18.2.2.1" class="pilcrow">¶</a></p>
</li>
              <li class="ulEmpty compact toc" id="section-toc.1-1.18.2.3">
                <p id="section-toc.1-1.18.2.3.1"><a href="#section-g.3" class="xref">G.3</a>.  <a href="#name-changes-in-suggestions-and-" class="xref">Changes in Suggestions and Other Informational Components</a><a href="#section-toc.1-1.18.2.3.1" class="pilcrow">¶</a></p>
</li>
            </ul>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.19">
            <p id="section-toc.1-1.19.1"><a href="#section-appendix.h" class="xref"></a><a href="#name-acknowledgements" class="xref">Acknowledgements</a><a href="#section-toc.1-1.19.1" class="pilcrow">¶</a></p>
</li>
          <li class="ulEmpty compact toc" id="section-toc.1-1.20">
            <p id="section-toc.1-1.20.1"><a href="#section-appendix.i" class="xref"></a><a href="#name-authors-addresses" class="xref">Authors' Addresses</a><a href="#section-toc.1-1.20.1" class="pilcrow">¶</a></p>
</li>
        </ul>
</nav>
</section>
</div>
<div id="introduction">
<section id="section-1">
      <h2 id="name-introduction">
<a href="#section-1" class="section-number selfRef">1. </a><a href="#name-introduction" class="section-name selfRef">Introduction</a>
      </h2>
<p id="section-1-1">There are hundreds of standardized formats for binary representation
of structured data (also known as binary serialization formats).  Of
those, some are for specific domains of information, while others are
generalized for arbitrary data.  In the IETF, probably the best-known
formats in the latter category are ASN.1's BER and DER <span>[<a href="#ASN.1" class="xref">ASN.1</a>]</span>.<a href="#section-1-1" class="pilcrow">¶</a></p>
<p id="section-1-2">The format defined here follows some specific design goals that are
not well met by current formats.  The underlying data model is an
extended version of the JSON data model <span>[<a href="#RFC8259" class="xref">RFC8259</a>]</span>.  It is important
to note that this is not a proposal that the grammar in RFC 8259 be
extended in general, since doing so would cause a significant
backwards incompatibility with already deployed JSON
documents. Instead, this document simply defines its own data model
that starts from JSON.<a href="#section-1-2" class="pilcrow">¶</a></p>
<p id="section-1-3"><a href="#comparison-app" class="xref">Appendix E</a> lists some existing binary formats and discusses
how well they do or do not fit the design objectives of the Concise
Binary Object Representation (CBOR).<a href="#section-1-3" class="pilcrow">¶</a></p>
<p id="section-1-4"> This document obsoletes <span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span>, providing editorial improvements, new 
   details, and errata fixes while keeping full compatibility with 
   the interchange format of RFC 7049.  It does not create a new version
   of the format.<a href="#section-1-4" class="pilcrow">¶</a></p>
<div id="objectives">
<section id="section-1.1">
        <h3 id="name-objectives">
<a href="#section-1.1" class="section-number selfRef">1.1. </a><a href="#name-objectives" class="section-name selfRef">Objectives</a>
        </h3>
<p id="section-1.1-1">The objectives of CBOR, roughly in decreasing order of importance,
are:<a href="#section-1.1-1" class="pilcrow">¶</a></p>
<ol start="1" type="1" class="normal type-1" id="section-1.1-2">
<li id="section-1.1-2.1">
            <p id="section-1.1-2.1.1">The representation must be able to unambiguously encode most common
data formats used in Internet standards.<a href="#section-1.1-2.1.1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-1.1-2.1.2.1">It must represent a reasonable set of basic data types and
structures using binary encoding.  "Reasonable" here is largely
influenced by the capabilities of JSON, with the major addition
of binary byte strings.  The structures supported are limited to
arrays and trees; loops and lattice-style graphs are not
supported.<a href="#section-1.1-2.1.2.1" class="pilcrow">¶</a>
</li>
              <li class="normal" id="section-1.1-2.1.2.2">There is no requirement that all data formats be uniquely
encoded; that is, it is acceptable that the number "7" might be
encoded in multiple different ways.<a href="#section-1.1-2.1.2.2" class="pilcrow">¶</a>
</li>
            </ul>
</li>
          <li id="section-1.1-2.2">
            <p id="section-1.1-2.2.1">The code for an encoder or decoder must be able to be compact in
order to support systems with very limited memory, processor power,
and instruction sets.<a href="#section-1.1-2.2.1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-1.1-2.2.2.1">An encoder and a decoder need to be implementable in a very
small amount of code (for example, in class 1 constrained nodes
as defined in <span>[<a href="#RFC7228" class="xref">RFC7228</a>]</span>).<a href="#section-1.1-2.2.2.1" class="pilcrow">¶</a>
</li>
              <li class="normal" id="section-1.1-2.2.2.2">The format should use contemporary machine representations of
data (for example, not requiring binary-to-decimal conversion).<a href="#section-1.1-2.2.2.2" class="pilcrow">¶</a>
</li>
            </ul>
</li>
          <li id="section-1.1-2.3">
            <p id="section-1.1-2.3.1">Data must be able to be decoded without a schema description.<a href="#section-1.1-2.3.1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-1.1-2.3.2.1">Similar to JSON, encoded data should be self-describing so that
a generic decoder can be written.<a href="#section-1.1-2.3.2.1" class="pilcrow">¶</a>
</li>
            </ul>
</li>
          <li id="section-1.1-2.4">
            <p id="section-1.1-2.4.1">The serialization must be reasonably compact, but data compactness
is secondary to code compactness for the encoder and decoder.<a href="#section-1.1-2.4.1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-1.1-2.4.2.1">"Reasonable" here is bounded by JSON as an upper bound in
              size and by the implementation complexity, which limits the
              amount of effort that can go into achieving that compactness.
              Using either general compression schemes or extensive
              bit-fiddling violates the complexity goals.<a href="#section-1.1-2.4.2.1" class="pilcrow">¶</a>
</li>
            </ul>
</li>
          <li id="section-1.1-2.5">
            <p id="section-1.1-2.5.1">The format must be applicable to both constrained nodes and
high-volume applications.<a href="#section-1.1-2.5.1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-1.1-2.5.2.1">This means it must be reasonably frugal in CPU usage for both
encoding and decoding.  This is relevant both for constrained
nodes and for potential usage in applications with a very high
volume of data.<a href="#section-1.1-2.5.2.1" class="pilcrow">¶</a>
</li>
            </ul>
</li>
          <li id="section-1.1-2.6">
            <p id="section-1.1-2.6.1">The format must support all JSON data types for conversion to and
from JSON.<a href="#section-1.1-2.6.1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-1.1-2.6.2.1">It must support a reasonable level of conversion as long as the
data represented is within the capabilities of JSON.  It must be
possible to define a unidirectional mapping towards JSON for all
types of data.<a href="#section-1.1-2.6.2.1" class="pilcrow">¶</a>
</li>
            </ul>
</li>
          <li id="section-1.1-2.7">
            <p id="section-1.1-2.7.1">The format must be extensible, and the extended data must be
decodable by earlier decoders.<a href="#section-1.1-2.7.1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-1.1-2.7.2.1">The format is designed for decades of use.<a href="#section-1.1-2.7.2.1" class="pilcrow">¶</a>
</li>
              <li class="normal" id="section-1.1-2.7.2.2">The format must support a form of extensibility that allows
fallback so that a decoder that does not understand an extension
can still decode the message.<a href="#section-1.1-2.7.2.2" class="pilcrow">¶</a>
</li>
              <li class="normal" id="section-1.1-2.7.2.3">The format must be able to be extended in the future by later
IETF standards.<a href="#section-1.1-2.7.2.3" class="pilcrow">¶</a>
</li>
            </ul>
</li>
        </ol>
</section>
</div>
<div id="terminology">
<section id="section-1.2">
        <h3 id="name-terminology">
<a href="#section-1.2" class="section-number selfRef">1.2. </a><a href="#name-terminology" class="section-name selfRef">Terminology</a>
        </h3>
<p id="section-1.2-1">The key words "<span class="bcp14">MUST</span>", "<span class="bcp14">MUST NOT</span>", 
        "<span class="bcp14">REQUIRED</span>", "<span class="bcp14">SHALL</span>", "<span class="bcp14">SHALL NOT</span>", "<span class="bcp14">SHOULD</span>", "<span class="bcp14">SHOULD NOT</span>", 
        "<span class="bcp14">RECOMMENDED</span>", "<span class="bcp14">NOT RECOMMENDED</span>",
        "<span class="bcp14">MAY</span>", and "<span class="bcp14">OPTIONAL</span>" in this document are to be interpreted as
        described in BCP 14 <span>[<a href="#RFC2119" class="xref">RFC2119</a>]</span> <span>[<a href="#RFC8174" class="xref">RFC8174</a>]</span> 
        when, and only when, they appear in all capitals, as shown here.<a href="#section-1.2-1" class="pilcrow">¶</a></p>
<p id="section-1.2-2">The term "byte" is used in its now-customary sense as a synonym for
"octet". All multi-byte values are encoded in network byte order (that
is, most significant byte first, also known as "big-endian").<a href="#section-1.2-2" class="pilcrow">¶</a></p>
<p id="section-1.2-3">This specification makes use of the following terminology:<a href="#section-1.2-3" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-1.2-4">
          <dt id="section-1.2-4.1">Data item:</dt>
          <dd style="margin-left: 1.5em" id="section-1.2-4.2">
  A single piece of CBOR data.  The structure of a data item may
contain zero, one, or more nested data items.  The term is used both
for the data item in representation format and for the abstract idea
that can be derived from that by a decoder; the former can be
addressed specifically by using the term "encoded data item".<a href="#section-1.2-4.2" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-1.2-4.3">Decoder:</dt>
          <dd style="margin-left: 1.5em" id="section-1.2-4.4">
  A process that decodes a well-formed encoded CBOR data item and makes it available to an
application.  Formally speaking, a decoder contains a parser to
break up the input using the syntax rules of CBOR, as well as a
semantic processor to prepare the data in a form suitable to the
application.<a href="#section-1.2-4.4" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-1.2-4.5">Encoder:</dt>
          <dd style="margin-left: 1.5em" id="section-1.2-4.6">
  A process that generates the (well-formed) representation format of a CBOR data
item from application information.<a href="#section-1.2-4.6" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-1.2-4.7">Data Stream:</dt>
          <dd style="margin-left: 1.5em" id="section-1.2-4.8">
  A sequence of zero or more data items, not further assembled into a
larger containing data item (see <span>[<a href="#RFC8742" class="xref">RFC8742</a>]</span> for one application).
The independent data items that make
up a data stream are sometimes also referred to as "top-level data
items".<a href="#section-1.2-4.8" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-1.2-4.9">Well-formed:</dt>
          <dd style="margin-left: 1.5em" id="section-1.2-4.10">
  A data item that follows the syntactic structure of CBOR.  A
well-formed data item uses the initial bytes and the byte strings
and/or data items that are implied by their values as defined in
CBOR and does not include following extraneous data. CBOR decoders
by definition only return contents from well-formed data items.<a href="#section-1.2-4.10" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-1.2-4.11">Valid:</dt>
          <dd style="margin-left: 1.5em" id="section-1.2-4.12">
  A data item that is well-formed and also follows the semantic
restrictions that apply to CBOR data items (<a href="#semantic-errors" class="xref">Section 5.3</a>).<a href="#section-1.2-4.12" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-1.2-4.13">Expected:</dt>
          <dd style="margin-left: 1.5em" id="section-1.2-4.14">
  Besides its normal English meaning, the term "expected" is used to
describe requirements beyond CBOR validity that an application has
on its input data.  Well-formed (processable at all), valid (checked
by a validity-checking generic decoder), and expected (checked by the
application) form a hierarchy of layers of acceptability.<a href="#section-1.2-4.14" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-1.2-4.15">Stream decoder:</dt>
          <dd style="margin-left: 1.5em" id="section-1.2-4.16">
  A process that decodes a data stream and makes each of the data
items in the sequence available to an application as they are
received.<a href="#section-1.2-4.16" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
</dl>
<p id="section-1.2-5">Terms and concepts for floating-point values such as Infinity, NaN
(not a number), negative zero, and subnormal are defined in <span>[<a href="#IEEE754" class="xref">IEEE754</a>]</span>.<a href="#section-1.2-5" class="pilcrow">¶</a></p>
<p id="section-1.2-6">Where bit arithmetic or data types are explained, this document uses
the notation familiar from the programming language C <span>[<a href="#C" class="xref">C</a>]</span>, except that
".." denotes a range that includes both ends given, and superscript
notation denotes exponentiation.  For example, 2 to the power of 64 is
notated: 2<sup>64</sup>.
In the plain-text version of this specification, superscript notation
is not available and therefore is rendered by a surrogate notation.
That notation is not optimized for this RFC; it is unfortunately
ambiguous with C's exclusive-or (which is only used in the appendices,
which in turn do not use exponentiation) and requires circumspection
from the reader of the plain-text version.<a href="#section-1.2-6" class="pilcrow">¶</a></p>
<p id="section-1.2-7">Examples and pseudocode
assume that signed integers use two's complement representation and
that right shifts of signed integers perform sign extension; these
assumptions are also specified in Sections 6.8.1 (basic.fundamental)
and 7.6.7 (expr.shift) of the 2020 version of C++ (currently available
as a final draft, <span>[<a href="#Cplusplus20" class="xref">Cplusplus20</a>]</span>).<a href="#section-1.2-7" class="pilcrow">¶</a></p>
<p id="section-1.2-8">Similar to the "0x" notation for
hexadecimal numbers, numbers in binary notation are prefixed with
"0b".  Underscores can be added to a number solely for
readability, so 0b00100001 (0x21) might be written 0b001_00001 to
emphasize the desired interpretation of the bits in the byte; in this
case, it is split into three bits and five bits.  Encoded CBOR data
items are sometimes given in the "0x" or "0b" notation; these values
are first interpreted as numbers as in C and are then interpreted as
byte strings in network byte order, including any leading zero bytes
expressed in the notation.<a href="#section-1.2-8" class="pilcrow">¶</a></p>
<p id="section-1.2-9">Words may be <em>italicized</em> for emphasis; in the plain text
        form of this specification, this is indicated by surrounding words
        with underscore characters.  Verbatim text (e.g., names from a
        programming language) may be set in <code>monospace</code> type; in plain
        text, this is approximated somewhat ambiguously by surrounding the
        text in double quotes (which also retain their usual meaning).<a href="#section-1.2-9" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
<div id="cbor-data-models">
<section id="section-2">
      <h2 id="name-cbor-data-models">
<a href="#section-2" class="section-number selfRef">2. </a><a href="#name-cbor-data-models" class="section-name selfRef">CBOR Data Models</a>
      </h2>
<p id="section-2-1">CBOR is explicit about its generic data model, which defines the set
of all data items that can be represented in CBOR.  Its basic generic
data model is extensible by the registration of "simple values" and
tags.  Applications can then create a subset of the resulting extended generic
data model to build their specific data models.<a href="#section-2-1" class="pilcrow">¶</a></p>
<p id="section-2-2">Within environments that can represent the data items in the generic
data model, generic CBOR encoders and decoders can be implemented
(which usually involves defining additional implementation data types
for those data items that do not already have a natural representation
in the environment).  The ability to provide generic encoders and
decoders is an explicit design goal of CBOR; however, many applications
will provide their own application-specific encoders and/or decoders.<a href="#section-2-2" class="pilcrow">¶</a></p>
<p id="section-2-3">In the basic (unextended) generic data model defined in 
<a href="#encoding" class="xref">Section 3</a>, a data item is one of
the following:<a href="#section-2-3" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-2-4.1">an integer in the range -2<sup>64</sup>..2<sup>64</sup>-1 inclusive<a href="#section-2-4.1" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-2-4.2">a simple value, identified by a number
between 0 and 255, but distinct from that number itself<a href="#section-2-4.2" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-2-4.3">a floating-point value, distinct from an integer, out of the set
representable by IEEE 754 binary64 (including non-finites) <span>[<a href="#IEEE754" class="xref">IEEE754</a>]</span><a href="#section-2-4.3" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-2-4.4">a sequence of zero or more bytes ("byte string")<a href="#section-2-4.4" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-2-4.5">a sequence of zero or more Unicode code points ("text string")<a href="#section-2-4.5" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-2-4.6">a sequence of zero or more data items ("array")<a href="#section-2-4.6" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-2-4.7">a mapping (mathematical function) from zero or more data items
("keys") each to a data item ("values"), ("map")<a href="#section-2-4.7" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-2-4.8">a tagged data item ("tag"), comprising a tag number (an integer in
the range 0..2<sup>64</sup>-1) and the tag content (a data item)<a href="#section-2-4.8" class="pilcrow">¶</a>
</li>
      </ul>
<p id="section-2-5">Note that integer and floating-point values are distinct in this
model, even if they have the same numeric value.<a href="#section-2-5" class="pilcrow">¶</a></p>
<p id="section-2-6">Also note that serialization variants are not visible at the generic
data model level.  This deliberate absence of visibility includes the number of bytes of the encoded
floating-point value. It also includes the choice of encoding for an "argument" (see
<a href="#encoding" class="xref">Section 3</a>) such as the encoding for an
integer, the encoding for the length of a text or byte string, the encoding for the number of elements
in an array or pairs in a map, or the encoding for a tag number.<a href="#section-2-6" class="pilcrow">¶</a></p>
<div id="extended-generic-data-models">
<section id="section-2.1">
        <h3 id="name-extended-generic-data-model">
<a href="#section-2.1" class="section-number selfRef">2.1. </a><a href="#name-extended-generic-data-model" class="section-name selfRef">Extended Generic Data Models</a>
        </h3>
<p id="section-2.1-1">This basic generic data model has been extended in this document by the registration
of a number of simple values and tag numbers, such as:<a href="#section-2.1-1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-2.1-2.1">
            <code>false</code>, <code>true</code>, <code>null</code>, and <code>undefined</code> 
(simple values identified by 20..23, <a href="#fpnocont" class="xref">Section 3.3</a>)<a href="#section-2.1-2.1" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-2.1-2.2">integer and floating-point values with a larger range and precision
than the above (tag numbers 2 to 5, <a href="#tags" class="xref">Section 3.4</a>)<a href="#section-2.1-2.2" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-2.1-2.3">application data types such as a point in time or 
date/time string defined in RFC 3339 (tag numbers 1 and 0, <a href="#tags" class="xref">Section 3.4</a>)<a href="#section-2.1-2.3" class="pilcrow">¶</a>
</li>
        </ul>
<p id="section-2.1-3">Additional elements of the extended generic data model can be (and have
been) defined via the IANA registries created for CBOR.  Even if such
an extension is unknown to a generic encoder or decoder, data items
using that extension can be passed to or from the application by
representing them at the application interface within the basic
generic data model, i.e., as generic simple values or
generic tags.<a href="#section-2.1-3" class="pilcrow">¶</a></p>
<p id="section-2.1-4">In other words, the basic generic data model is stable as defined in
this document, while the extended generic data model expands by the
registration of new simple values or tag numbers, but never shrinks.<a href="#section-2.1-4" class="pilcrow">¶</a></p>
<p id="section-2.1-5">While there is a strong expectation that generic encoders and decoders
can represent <code>false</code>, <code>true</code>, and <code>null</code> (<code>undefined</code> is intentionally
omitted) in the form appropriate for their programming environment,
the implementation of the data model extensions created by tags is truly
optional and a matter of implementation quality.<a href="#section-2.1-5" class="pilcrow">¶</a></p>
</section>
</div>
<div id="specific-data-models">
<section id="section-2.2">
        <h3 id="name-specific-data-models">
<a href="#section-2.2" class="section-number selfRef">2.2. </a><a href="#name-specific-data-models" class="section-name selfRef">Specific Data Models</a>
        </h3>
<p id="section-2.2-1">The specific data model for a CBOR-based protocol usually takes a subset of the
extended generic data model and assigns application semantics to the
data items within this subset and its components.  
   When documenting such specific data models and specifying the types 
   of data items, it is preferable to identify the types by their 
   generic data model names ("negative integer", "array") instead of 
   referring to aspects of their CBOR representation ("major type 1", 
   "major type 4").<a href="#section-2.2-1" class="pilcrow">¶</a></p>
<p id="section-2.2-2">   Specific data models can also specify value equivalency (including 
   values of different types) for the purposes of map keys and encoder freedom. For 
example, in the generic data model, a valid map <span class="bcp14">MAY</span> have both <code>0</code> and
<code>0.0</code> as keys, and an encoder <span class="bcp14">MUST NOT</span> encode <code>0.0</code> as an integer
(major type 0, <a href="#majortypes" class="xref">Section 3.1</a>).  However, if a specific data model
declares that floating-point and integer representations of integral
values are equivalent, using both map keys <code>0</code> and <code>0.0</code> in a single
map would be considered
duplicates, even while encoded as different major types, and so invalid; and an encoder could encode integral-valued
floats as integers or vice versa, perhaps to save encoded bytes.<a href="#section-2.2-2" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
<div id="encoding">
<section id="section-3">
      <h2 id="name-specification-of-the-cbor-e">
<a href="#section-3" class="section-number selfRef">3. </a><a href="#name-specification-of-the-cbor-e" class="section-name selfRef">Specification of the CBOR Encoding</a>
      </h2>
<p id="section-3-1">A CBOR data item (<a href="#cbor-data-models" class="xref">Section 2</a>) is encoded to or decoded from
a byte string carrying a well-formed encoded data item as described in this section.  The encoding is
summarized in <a href="#jumptable" class="xref">Table 7</a> in <a href="#jump-table" class="xref">Appendix B</a>, indexed by the initial byte.  An encoder <span class="bcp14">MUST</span> produce only well-formed
encoded data items.  A decoder <span class="bcp14">MUST NOT</span> return a decoded data item when it
encounters input that is not a well-formed encoded CBOR data item (this does
not detract from the usefulness of diagnostic and recovery tools that
might make available some information from a damaged encoded CBOR data item).<a href="#section-3-1" class="pilcrow">¶</a></p>
<p id="section-3-2">The initial byte of each encoded data item contains both information
about the major type (the high-order 3 bits, described in
<a href="#majortypes" class="xref">Section 3.1</a>) and additional information (the low-order 5 bits).
With a few exceptions, the additional information's value
describes how to load an unsigned integer "argument":<a href="#section-3-2" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-3-3">
        <dt id="section-3-3.1">Less than 24:</dt>
        <dd style="margin-left: 1.5em" id="section-3-3.2">
  The argument's value is the value of the additional information.<a href="#section-3-3.2" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
<dt id="section-3-3.3">24, 25, 26, or 27:</dt>
        <dd style="margin-left: 1.5em" id="section-3-3.4">
  The argument's value is held in the following 1, 2, 4, or 8 bytes,
respectively, in network byte order.  For major type 7 and
additional information value 25, 26, 27, these bytes are not used as
an integer argument, but as a floating-point value (see
<a href="#fpnocont" class="xref">Section 3.3</a>).<a href="#section-3-3.4" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
<dt id="section-3-3.5">28, 29, 30:</dt>
        <dd style="margin-left: 1.5em" id="section-3-3.6">
  These values are reserved for future additions to the CBOR format.
In the present version of CBOR, the encoded item is not well-formed.<a href="#section-3-3.6" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
<dt id="section-3-3.7">31:</dt>
        <dd style="margin-left: 1.5em" id="section-3-3.8">
  No argument value is derived.
If the major type is 0, 1, or 6, the encoded item is not
well-formed.  For major types 2 to 5, the item's length is
indefinite, and for major type 7, the byte does not constitute a data
item at all but terminates an indefinite-length item; all are
described in <a href="#indefinite" class="xref">Section 3.2</a>.<a href="#section-3-3.8" class="pilcrow">¶</a>
</dd>
      <dd class="break"></dd>
</dl>
<p id="section-3-4">The initial byte and any additional bytes consumed to construct the
argument are collectively referred to as the <em>head</em> of the data item.<a href="#section-3-4" class="pilcrow">¶</a></p>
<p id="section-3-5">The meaning of this argument depends on the major type.
For example, in major type 0, the argument is the value of the data
item itself (and in major type 1, the value of the data item is
computed from the argument); in major type 2 and 3, it gives the length
of the string data in bytes that follow; and in major types 4 and 5, it is used to
determine the number of data items enclosed.<a href="#section-3-5" class="pilcrow">¶</a></p>
<p id="section-3-6">If the encoded sequence of bytes ends before the end of a data item,
that item is not well-formed. If the encoded
sequence of bytes still has bytes remaining
after the outermost encoded item is decoded, that encoding is not a
single well-formed CBOR item. Depending on the application, the decoder may either
treat the encoding as not well-formed or just identify the start of
the remaining bytes to the application.<a href="#section-3-6" class="pilcrow">¶</a></p>
<p id="section-3-7">A CBOR decoder implementation can be based on a jump table with all
256 defined values for the initial byte (<a href="#jumptable" class="xref">Table 7</a>).  A decoder in
a constrained implementation can instead use the structure of the
initial byte and following bytes for more compact code (see
<a href="#pseudocode" class="xref">Appendix C</a> for a rough impression of how this could look).<a href="#section-3-7" class="pilcrow">¶</a></p>
<div id="majortypes">
<section id="section-3.1">
        <h3 id="name-major-types">
<a href="#section-3.1" class="section-number selfRef">3.1. </a><a href="#name-major-types" class="section-name selfRef">Major Types</a>
        </h3>
<p id="section-3.1-1">The following lists the major types and the additional information and
other bytes associated with the type.<a href="#section-3.1-1" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlNewline" id="section-3.1-2">
          <dt id="section-3.1-2.1">Major type 0:</dt>
          <dd style="margin-left: 1.5em" id="section-3.1-2.2">
  An unsigned integer in the range 0..2<sup>64</sup>-1 inclusive.  The value of the
encoded item is the argument itself.  For example, the
integer 10 is denoted as the one byte 0b000_01010 (major type 0,
additional information 10).  The integer 500 would be 0b000_11001
(major type 0, additional information 25) followed by the two bytes
0x01f4, which is 500 in decimal.<a href="#section-3.1-2.2" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-3.1-2.3">Major type 1:</dt>
          <dd style="margin-left: 1.5em" id="section-3.1-2.4">
  A negative integer in the range -2<sup>64</sup>..-1 inclusive.  The value of
the item is -1 minus the argument.  For example, the integer
-500 would be 0b001_11001 (major type 1, additional information 25)
followed by the two bytes 0x01f3, which is 499 in decimal.<a href="#section-3.1-2.4" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-3.1-2.5">Major type 2:</dt>
          <dd style="margin-left: 1.5em" id="section-3.1-2.6">
  A byte string.  The number of bytes in the string is equal to the
argument.  For example, a byte
string whose length is 5 would have an initial byte of 0b010_00101
(major type 2, additional information 5 for the length), followed by
5 bytes of binary content. A byte string whose length is 500 would
have 3 initial bytes of 0b010_11001 (major type 2, additional
information 25 to indicate a two-byte length) followed by the two
bytes 0x01f4 for a length of 500, followed by 500 bytes of binary
content.<a href="#section-3.1-2.6" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-3.1-2.7">Major type 3:</dt>
          <dd style="margin-left: 1.5em" id="section-3.1-2.8">
  A text string (<a href="#cbor-data-models" class="xref">Section 2</a>) encoded as UTF-8
<span>[<a href="#RFC3629" class="xref">RFC3629</a>]</span>. The number of bytes in the string is equal to the
argument.  A string containing an invalid UTF-8 sequence is
well-formed but invalid (<a href="#terminology" class="xref">Section 1.2</a>). This type is provided for
systems that need to interpret or display human-readable text, and
allows the differentiation between unstructured bytes and text that
has a specified repertoire (that of Unicode) and encoding (UTF-8).  In contrast to formats
such as JSON, the Unicode characters in this type are never
escaped. Thus, a newline character (U+000A) is always represented in
a string as the byte 0x0a, and never as the bytes 0x5c6e (the
characters "\" and "n") nor as 0x5c7530303061 (the characters "\",
"u", "0", "0", "0", and "a").<a href="#section-3.1-2.8" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-3.1-2.9">Major type 4:</dt>
          <dd style="margin-left: 1.5em" id="section-3.1-2.10">
  An array of data items.  In other formats, arrays are also called lists, sequences, or
tuples (a "CBOR sequence" is something slightly different, though <span>[<a href="#RFC8742" class="xref">RFC8742</a>]</span>).
The argument is the number of data items in the
array.  Items in an
array do not need to all be of the same type.  For example, an array
that contains 10 items of any type would have an initial byte of
0b100_01010 (major type 4, additional information 10 for the
length) followed by the 10 remaining items.<a href="#section-3.1-2.10" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-3.1-2.11">Major type 5:</dt>
          <dd style="margin-left: 1.5em" id="section-3.1-2.12">
  A map of pairs of data items. Maps are also called tables,
dictionaries, hashes, or objects (in JSON).  A map is comprised of
pairs of data items, each pair consisting of a key that is
immediately followed by a value.  The argument is the number
of <em>pairs</em> of data items in the map.  For
example, a map that contains 9 pairs would have an initial byte of
0b101_01001 (major type 5, additional information 9 for the
number of pairs) followed by the 18 remaining items. The first item
is the first key, the second item is the first value, the third item
is the second key, and so on.  Because items in a map come in pairs,
their total number is always even: a map that contains an odd
number of items (no value data present after the last key data item) is not well-formed.
A map that has duplicate keys may be
well-formed, but it is not valid, and thus it causes indeterminate
decoding; see also <a href="#map-keys" class="xref">Section 5.6</a>.<a href="#section-3.1-2.12" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-3.1-2.13">Major type 6:</dt>
          <dd style="margin-left: 1.5em" id="section-3.1-2.14">
  A tagged data item ("tag") whose tag number, an integer in the range
0..2<sup>64</sup>-1 inclusive, is the argument and
whose enclosed data item (<em>tag content</em>) is the single encoded data item that follows the head.
See <a href="#tags" class="xref">Section 3.4</a>.<a href="#section-3.1-2.14" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-3.1-2.15">Major type 7:</dt>
          <dd style="margin-left: 1.5em" id="section-3.1-2.16">
  Floating-point numbers and simple values, as well as the "break"
stop code.  See <a href="#fpnocont" class="xref">Section 3.3</a>.<a href="#section-3.1-2.16" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
</dl>
<p id="section-3.1-3">These eight major types lead to a simple table showing which of the
256 possible values for the initial byte of a data item are used
(<a href="#jumptable" class="xref">Table 7</a>).<a href="#section-3.1-3" class="pilcrow">¶</a></p>
<p id="section-3.1-4">In major types 6 and 7, many of the possible values are reserved for
future specification. See <a href="#ianacons" class="xref">Section 9</a> for more information on these
values.<a href="#section-3.1-4" class="pilcrow">¶</a></p>
<p id="section-3.1-5"><a href="#major-type-table" class="xref">Table 1</a> summarizes the major types defined by CBOR,
ignoring <a href="#indefinite" class="xref">Section 3.2</a> for now.  The number N in this table stands
for the argument.<a href="#section-3.1-5" class="pilcrow">¶</a></p>
<span id="name-overview-over-the-definite-"></span><div id="major-type-table">
<table class="center" id="table-1">
          <caption>
<a href="#table-1" class="selfRef">Table 1</a>:
<a href="#name-overview-over-the-definite-" class="selfRef">Overview over the Definite-Length Use of CBOR Major Types (N = Argument)</a>
          </caption>
<thead>
            <tr>
              <th class="text-left" rowspan="1" colspan="1">Major Type</th>
              <th class="text-left" rowspan="1" colspan="1">Meaning</th>
              <th class="text-left" rowspan="1" colspan="1">Content</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">0</td>
              <td class="text-left" rowspan="1" colspan="1">unsigned integer N</td>
              <td class="text-left" rowspan="1" colspan="1">-</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">1</td>
              <td class="text-left" rowspan="1" colspan="1">negative integer -1-N</td>
              <td class="text-left" rowspan="1" colspan="1">-</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">2</td>
              <td class="text-left" rowspan="1" colspan="1">byte string</td>
              <td class="text-left" rowspan="1" colspan="1">N bytes</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">3</td>
              <td class="text-left" rowspan="1" colspan="1">text string</td>
              <td class="text-left" rowspan="1" colspan="1">N bytes (UTF-8 text)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">4</td>
              <td class="text-left" rowspan="1" colspan="1">array</td>
              <td class="text-left" rowspan="1" colspan="1">N data items (elements)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">5</td>
              <td class="text-left" rowspan="1" colspan="1">map</td>
              <td class="text-left" rowspan="1" colspan="1">2N data items (key/value pairs)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">6</td>
              <td class="text-left" rowspan="1" colspan="1">tag of number N</td>
              <td class="text-left" rowspan="1" colspan="1">1 data item</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">7</td>
              <td class="text-left" rowspan="1" colspan="1">simple/float</td>
              <td class="text-left" rowspan="1" colspan="1">-</td>
            </tr>
          </tbody>
        </table>
</div>
</section>
</div>
<div id="indefinite">
<section id="section-3.2">
        <h3 id="name-indefinite-lengths-for-some">
<a href="#section-3.2" class="section-number selfRef">3.2. </a><a href="#name-indefinite-lengths-for-some" class="section-name selfRef">Indefinite Lengths for Some Major Types</a>
        </h3>
<p id="section-3.2-1">Four CBOR items (arrays, maps, byte strings, and text strings) can be
encoded with an indefinite length using additional information
value 31.  This is useful if the encoding of the item needs to begin
before the number of items inside the array or map, or the total
length of the string, is known.  (The ability to start sending a data
item before all of it is known is often
referred to as "streaming" within that data item.)<a href="#section-3.2-1" class="pilcrow">¶</a></p>
<p id="section-3.2-2">Indefinite-length arrays and maps are dealt with differently than
indefinite-length strings (byte strings and text strings).<a href="#section-3.2-2" class="pilcrow">¶</a></p>
<div id="break">
<section id="section-3.2.1">
          <h4 id="name-the-break-stop-code">
<a href="#section-3.2.1" class="section-number selfRef">3.2.1. </a><a href="#name-the-break-stop-code" class="section-name selfRef">The "break" Stop Code</a>
          </h4>
<p id="section-3.2.1-1">The "break" stop code is encoded with major type 7 and additional
information value 31 (0b111_11111). It is not itself a data item: it
is just a syntactic feature to close an indefinite-length item.<a href="#section-3.2.1-1" class="pilcrow">¶</a></p>
<p id="section-3.2.1-2">If the "break" stop code appears where a data item is expected,
          other than directly inside an indefinite-length string, array, or
          map -- for example, directly inside a definite-length array or map
          -- the enclosing item is not well-formed.<a href="#section-3.2.1-2" class="pilcrow">¶</a></p>
</section>
</div>
<div id="indef">
<section id="section-3.2.2">
          <h4 id="name-indefinite-length-arrays-an">
<a href="#section-3.2.2" class="section-number selfRef">3.2.2. </a><a href="#name-indefinite-length-arrays-an" class="section-name selfRef">Indefinite-Length Arrays and Maps</a>
          </h4>
<p id="section-3.2.2-1">Indefinite-length arrays and maps are represented using their major
type with the additional information value of 31, followed by an
arbitrary-length sequence of zero or more items for an array or key/value pairs for
a map, followed by the "break" stop code (<a href="#break" class="xref">Section 3.2.1</a>).  In other words, indefinite-length
arrays and maps look identical to other arrays and maps except for
beginning with the additional information value of 31 and ending with the
"break" stop code.<a href="#section-3.2.2-1" class="pilcrow">¶</a></p>
<p id="section-3.2.2-2">If the "break" stop code appears after a key in a map, in place of that
key's value, the map is not well-formed.<a href="#section-3.2.2-2" class="pilcrow">¶</a></p>
<p id="section-3.2.2-3">There is no restriction against nesting indefinite-length
array or map items.  A "break" only terminates a single item, so
nested indefinite-length items need exactly as many "break" stop codes
as there are type bytes starting an indefinite-length item.<a href="#section-3.2.2-3" class="pilcrow">¶</a></p>
<p id="section-3.2.2-4">For example, assume an encoder wants to represent the abstract array
[1, [2, 3], [4, 5]].  The definite-length encoding would be
0x8301820203820405:<a href="#section-3.2.2-4" class="pilcrow">¶</a></p>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.2.2-5">
<pre>
83        -- Array of length 3
   01     -- 1
   82     -- Array of length 2
      02  -- 2
      03  -- 3
   82     -- Array of length 2
      04  -- 4
      05  -- 5
</pre><a href="#section-3.2.2-5" class="pilcrow">¶</a>
</div>
<p id="section-3.2.2-6">Indefinite-length encoding could be applied independently to each of
the three arrays encoded in this data item, as required, leading to
representations such as:<a href="#section-3.2.2-6" class="pilcrow">¶</a></p>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.2.2-7">
<pre>
0x9f018202039f0405ffff
9F        -- Start indefinite-length array
   01     -- 1
   82     -- Array of length 2
      02  -- 2
      03  -- 3
   9F     -- Start indefinite-length array
      04  -- 4
      05  -- 5
      FF  -- "break" (inner array)
   FF     -- "break" (outer array)
</pre><a href="#section-3.2.2-7" class="pilcrow">¶</a>
</div>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.2.2-8">
<pre>
0x9f01820203820405ff
9F        -- Start indefinite-length array
   01     -- 1
   82     -- Array of length 2
      02  -- 2
      03  -- 3
   82     -- Array of length 2
      04  -- 4
      05  -- 5
   FF     -- "break"
</pre><a href="#section-3.2.2-8" class="pilcrow">¶</a>
</div>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.2.2-9">
<pre>
0x83018202039f0405ff
83        -- Array of length 3
   01     -- 1
   82     -- Array of length 2
      02  -- 2
      03  -- 3
   9F     -- Start indefinite-length array
      04  -- 4
      05  -- 5
      FF  -- "break"
</pre><a href="#section-3.2.2-9" class="pilcrow">¶</a>
</div>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.2.2-10">
<pre>
0x83019f0203ff820405
83        -- Array of length 3
   01     -- 1
   9F     -- Start indefinite-length array
      02  -- 2
      03  -- 3
      FF  -- "break"
   82     -- Array of length 2
      04  -- 4
      05  -- 5
</pre><a href="#section-3.2.2-10" class="pilcrow">¶</a>
</div>
<p id="section-3.2.2-11">An example of an indefinite-length map (that happens to have two
key/value pairs) might be:<a href="#section-3.2.2-11" class="pilcrow">¶</a></p>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.2.2-12">
<pre>
0xbf6346756ef563416d7421ff
BF           -- Start indefinite-length map
   63        -- First key, UTF-8 string length 3
      46756e --   "Fun"
   F5        -- First value, true
   63        -- Second key, UTF-8 string length 3
      416d74 --   "Amt"
   21        -- Second value, -2
   FF        -- "break"
</pre><a href="#section-3.2.2-12" class="pilcrow">¶</a>
</div>
</section>
</div>
<div id="indefinite-length-byte-strings-and-text-strings">
<section id="section-3.2.3">
          <h4 id="name-indefinite-length-byte-stri">
<a href="#section-3.2.3" class="section-number selfRef">3.2.3. </a><a href="#name-indefinite-length-byte-stri" class="section-name selfRef">Indefinite-Length Byte Strings and Text Strings</a>
          </h4>
<p id="section-3.2.3-1">Indefinite-length strings are represented by a byte containing the
major type for byte string or text string with an additional
information value of 31, followed by a series of zero or more strings
of the specified type ("chunks") that have definite lengths, and
finished by the "break" stop code (<a href="#break" class="xref">Section 3.2.1</a>).  The data item
represented by the indefinite-length string is the concatenation of
the chunks.  If no chunks are present, the data item is an empty
string of the specified type.  Zero-length chunks, while not
particularly useful, are permitted.<a href="#section-3.2.3-1" class="pilcrow">¶</a></p>
<p id="section-3.2.3-2">If any item between the indefinite-length string indicator
(0b010_11111 or 0b011_11111) and the "break" stop code is not a definite-length
string item of the same major type, the string is not well-formed.<a href="#section-3.2.3-2" class="pilcrow">¶</a></p>
<p id="section-3.2.3-3">The design does not allow nesting
indefinite-length strings as chunks into indefinite-length strings.
If it were allowed, it would require decoder implementations to keep a stack, or at
least a count, of nesting levels.  It is unnecessary on the
encoder side because the inner indefinite-length string would consist of
chunks, and these could instead be put directly into the outer indefinite-length
string.<a href="#section-3.2.3-3" class="pilcrow">¶</a></p>
<p id="section-3.2.3-4">If any definite-length text string inside an indefinite-length text
string is invalid, the indefinite-length text string is invalid.  Note
that this implies that the UTF-8 bytes of a single Unicode code point
(scalar value) cannot be spread between chunks: a new chunk of a text
string can only be started at a code point boundary.<a href="#section-3.2.3-4" class="pilcrow">¶</a></p>
<p id="section-3.2.3-5">For example, assume an encoded data item consisting of the bytes:<a href="#section-3.2.3-5" class="pilcrow">¶</a></p>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.2.3-6">
<pre>
0b010_11111 0b010_00100 0xaabbccdd 0b010_00011 0xeeff99 0b111_11111
5F              -- Start indefinite-length byte string
   44           -- Byte string of length 4
      aabbccdd  -- Bytes content
   43           -- Byte string of length 3
      eeff99    -- Bytes content
   FF           -- "break"
</pre><a href="#section-3.2.3-6" class="pilcrow">¶</a>
</div>
<p id="section-3.2.3-7">After decoding, this results in a single byte string with seven bytes:
0xaabbccddeeff99.<a href="#section-3.2.3-7" class="pilcrow">¶</a></p>
</section>
</div>
<div id="summary-of-indefinite-length-use-of-major-types">
<section id="section-3.2.4">
          <h4 id="name-summary-of-indefinite-lengt">
<a href="#section-3.2.4" class="section-number selfRef">3.2.4. </a><a href="#name-summary-of-indefinite-lengt" class="section-name selfRef">Summary of Indefinite-Length Use of Major Types</a>
          </h4>
<p id="section-3.2.4-1"><a href="#major-type-indef-table" class="xref">Table 2</a> summarizes the major types defined by CBOR as
used for indefinite-length encoding (with additional information set
to 31).<a href="#section-3.2.4-1" class="pilcrow">¶</a></p>
<span id="name-overview-of-the-indefinite-"></span><div id="major-type-indef-table">
<table class="center" id="table-2">
            <caption>
<a href="#table-2" class="selfRef">Table 2</a>:
<a href="#name-overview-of-the-indefinite-" class="selfRef">Overview of the Indefinite-Length Use of CBOR Major Types (Additional Information = 31)</a>
            </caption>
<thead>
              <tr>
                <th class="text-left" rowspan="1" colspan="1">Major Type</th>
                <th class="text-left" rowspan="1" colspan="1">Meaning</th>
                <th class="text-left" rowspan="1" colspan="1">Enclosed up to "break" Stop Code</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td class="text-left" rowspan="1" colspan="1">0</td>
                <td class="text-left" rowspan="1" colspan="1">(not well-formed)</td>
                <td class="text-left" rowspan="1" colspan="1">-</td>
              </tr>
              <tr>
                <td class="text-left" rowspan="1" colspan="1">1</td>
                <td class="text-left" rowspan="1" colspan="1">(not well-formed)</td>
                <td class="text-left" rowspan="1" colspan="1">-</td>
              </tr>
              <tr>
                <td class="text-left" rowspan="1" colspan="1">2</td>
                <td class="text-left" rowspan="1" colspan="1">byte string</td>
                <td class="text-left" rowspan="1" colspan="1">definite-length byte strings</td>
              </tr>
              <tr>
                <td class="text-left" rowspan="1" colspan="1">3</td>
                <td class="text-left" rowspan="1" colspan="1">text string</td>
                <td class="text-left" rowspan="1" colspan="1">definite-length text strings</td>
              </tr>
              <tr>
                <td class="text-left" rowspan="1" colspan="1">4</td>
                <td class="text-left" rowspan="1" colspan="1">array</td>
                <td class="text-left" rowspan="1" colspan="1">data items (elements)</td>
              </tr>
              <tr>
                <td class="text-left" rowspan="1" colspan="1">5</td>
                <td class="text-left" rowspan="1" colspan="1">map</td>
                <td class="text-left" rowspan="1" colspan="1">data items (key/value pairs)</td>
              </tr>
              <tr>
                <td class="text-left" rowspan="1" colspan="1">6</td>
                <td class="text-left" rowspan="1" colspan="1">(not well-formed)</td>
                <td class="text-left" rowspan="1" colspan="1">-</td>
              </tr>
              <tr>
                <td class="text-left" rowspan="1" colspan="1">7</td>
                <td class="text-left" rowspan="1" colspan="1">"break" stop code</td>
                <td class="text-left" rowspan="1" colspan="1">-</td>
              </tr>
            </tbody>
          </table>
</div>
</section>
</div>
</section>
</div>
<div id="fpnocont">
<section id="section-3.3">
        <h3 id="name-floating-point-numbers-and-">
<a href="#section-3.3" class="section-number selfRef">3.3. </a><a href="#name-floating-point-numbers-and-" class="section-name selfRef">Floating-Point Numbers and Values with No Content</a>
        </h3>
<p id="section-3.3-1">Major type 7 is for two types of data: floating-point numbers and
"simple values" that do not need any content.  Each value of the 5-bit
additional information in the initial byte has its own separate
meaning, as defined in <a href="#fpnoconttbl" class="xref">Table 3</a>.  Like the major types for
integers, items of this major type do not carry content data; all the
information is in the initial bytes (the head).<a href="#section-3.3-1" class="pilcrow">¶</a></p>
<span id="name-values-for-additional-infor"></span><div id="fpnoconttbl">
<table class="center" id="table-3">
          <caption>
<a href="#table-3" class="selfRef">Table 3</a>:
<a href="#name-values-for-additional-infor" class="selfRef">Values for Additional Information in Major Type 7</a>
          </caption>
<thead>
            <tr>
              <th class="text-left" rowspan="1" colspan="1">5-Bit Value</th>
              <th class="text-left" rowspan="1" colspan="1">Semantics</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">0..23</td>
              <td class="text-left" rowspan="1" colspan="1">Simple value (value 0..23)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">24</td>
              <td class="text-left" rowspan="1" colspan="1">Simple value (value 32..255 in following byte)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">25</td>
              <td class="text-left" rowspan="1" colspan="1">IEEE 754 Half-Precision Float (16 bits follow)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">26</td>
              <td class="text-left" rowspan="1" colspan="1">IEEE 754 Single-Precision Float (32 bits follow)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">27</td>
              <td class="text-left" rowspan="1" colspan="1">IEEE 754 Double-Precision Float (64 bits follow)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">28-30</td>
              <td class="text-left" rowspan="1" colspan="1">Reserved, not well-formed in the present document</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">31</td>
              <td class="text-left" rowspan="1" colspan="1">"break" stop code for indefinite-length items (<a href="#break" class="xref">Section 3.2.1</a>)</td>
            </tr>
          </tbody>
        </table>
</div>
<p id="section-3.3-3">As with all other major types, the 5-bit value 24 signifies a
single-byte extension: it is followed by an additional byte to
represent the simple value. (To minimize confusion, only the values 32
to 255 are used.)  This maintains the structure of the initial bytes:
as for the other major types, the length of these always depends on
the additional information in the first byte. <a href="#fpnoconttbl2" class="xref">Table 4</a> lists
the numeric values assigned and available for simple values.<a href="#section-3.3-3" class="pilcrow">¶</a></p>
<span id="name-simple-values"></span><div id="fpnoconttbl2">
<table class="center" id="table-4">
          <caption>
<a href="#table-4" class="selfRef">Table 4</a>:
<a href="#name-simple-values" class="selfRef">Simple Values</a>
          </caption>
<thead>
            <tr>
              <th class="text-left" rowspan="1" colspan="1">Value</th>
              <th class="text-left" rowspan="1" colspan="1">Semantics</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">0..19</td>
              <td class="text-left" rowspan="1" colspan="1">(unassigned)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">20</td>
              <td class="text-left" rowspan="1" colspan="1">false</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">21</td>
              <td class="text-left" rowspan="1" colspan="1">true</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">22</td>
              <td class="text-left" rowspan="1" colspan="1">null</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">23</td>
              <td class="text-left" rowspan="1" colspan="1">undefined</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">24..31</td>
              <td class="text-left" rowspan="1" colspan="1">(reserved)</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">32..255</td>
              <td class="text-left" rowspan="1" colspan="1">(unassigned)</td>
            </tr>
          </tbody>
        </table>
</div>
<p id="section-3.3-5">An encoder <span class="bcp14">MUST NOT</span> issue two-byte sequences that
        start with 0xf8 (major type 7, additional information 24) and continue
        with a byte less than 0x20 (32 decimal).  Such sequences are not
        well-formed.  (This implies that an encoder cannot encode <code>false</code>, <code>true</code>,
        <code>null</code>, or <code>undefined</code> in two-byte sequences and that only the one-byte
        variants of these are well-formed; more generally speaking, each
        simple value only has a single representation variant).<a href="#section-3.3-5" class="pilcrow">¶</a></p>
<p id="section-3.3-6">The 5-bit values of 25, 26, and 27 are for 16-bit, 32-bit, and 64-bit
IEEE 754 binary floating-point values <span>[<a href="#IEEE754" class="xref">IEEE754</a>]</span>.  These floating-point values
are encoded in the additional bytes of the appropriate size.  (See
<a href="#half-precision" class="xref">Appendix D</a> for some information about 16-bit floating-point numbers.)<a href="#section-3.3-6" class="pilcrow">¶</a></p>
</section>
</div>
<div id="tags">
<section id="section-3.4">
        <h3 id="name-tagging-of-items">
<a href="#section-3.4" class="section-number selfRef">3.4. </a><a href="#name-tagging-of-items" class="section-name selfRef">Tagging of Items</a>
        </h3>
<p id="section-3.4-1">In CBOR, a data item can be enclosed by a tag to give it some
additional semantics, as uniquely identified by a <em>tag number</em>.
The tag is major type 6, its argument (<a href="#encoding" class="xref">Section 3</a>) indicates the tag
number, and it contains a single enclosed data item, the
<em>tag content</em>.
(If a tag requires further structure to its content, this structure is
provided by the enclosed data item.)
We use the term <em>tag</em> for the entire data item consisting of both a
tag number and the tag content: the tag content is the data item that
is being tagged.<a href="#section-3.4-1" class="pilcrow">¶</a></p>
<p id="section-3.4-2">For example, assume that a byte string of length 12 is marked with a
tag of number 2 to indicate it is an unsigned <em>bignum</em> (<a href="#bignums" class="xref">Section 3.4.3</a>).
The encoded data item would start with a byte 0b110_00010 (major type
6, additional information 2 for the tag number) followed by the
encoded tag content: 0b010_01100 (major type 2, additional information
12 for the length) followed by the 12 bytes of the bignum.<a href="#section-3.4-2" class="pilcrow">¶</a></p>
<p id="section-3.4-3">In the extended generic data model, a tag number's
definition describes the additional semantics
conveyed with the tag number.
These semantics may include equivalence of some tagged data
items with other data items, including some that can be
represented in the basic generic data model.  For instance, 0xc24101,
a bignum the tag content of which is the byte string with the single
byte 0x01, is equivalent to an integer 1, which could also be encoded
as 0x01, 0x1801, or 0x190001.
The tag definition may specify a preferred
serialization (<a href="#preferred" class="xref">Section 4.1</a>) that is recommended for generic
encoders; this may prefer basic generic data model representations
over ones that employ a tag.<a href="#section-3.4-3" class="pilcrow">¶</a></p>
<p id="section-3.4-4">The tag definition usually defines which nested data items are
valid for such tags.  Tag definitions may restrict their content to a
very specific syntactic structure, as the tags defined in this
document do, or they may define their content more semantically.  An
example for the latter is how tags 40 and 1040 accept multiple ways to
represent arrays <span>[<a href="#RFC8746" class="xref">RFC8746</a>]</span>.<a href="#section-3.4-4" class="pilcrow">¶</a></p>
<p id="section-3.4-5">As a matter of convention, many tags do not accept <code>null</code> or <code>undefined</code>
values as tag content; instead, the expectation is that a <code>null</code> or
<code>undefined</code> value can be used in place of the entire tag; <a href="#epochdatetimesect" class="xref">Section 3.4.2</a> 
provides some further considerations for one specific tag about the
   handling of this convention in application protocols and in mapping
   to platform types.<a href="#section-3.4-5" class="pilcrow">¶</a></p>
<p id="section-3.4-6">Decoders do not need to understand tags of every tag number, and tags may be of
little value in applications where the implementation creating a
particular CBOR data item and the implementation decoding that stream
know the semantic meaning of each item in the data flow. The primary
purpose of tags in this specification is to define common data types such as
dates. A secondary purpose is to provide conversion hints when it is
foreseen that the CBOR data item needs to be translated into a
different format, requiring hints about the content of items.
Understanding the semantics of tags is
optional for a decoder; it can simply present both the tag number and
the tag content to the application, without interpreting the additional
semantics of the tag.<a href="#section-3.4-6" class="pilcrow">¶</a></p>
<p id="section-3.4-7">A tag applies semantics to the data item it encloses.
Tags can nest:  if tag A encloses tag B, which encloses data item C,
tag A applies to the result of applying tag B on data item C.<a href="#section-3.4-7" class="pilcrow">¶</a></p>
<p id="section-3.4-8">IANA maintains a registry of tag numbers as described in <a href="#ianatags" class="xref">Section 9.2</a>.
<a href="#tagvalues" class="xref">Table 5</a> provides a list of tag numbers 
that were defined in <span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span> with definitions in
the rest of this section.
(Tag number 35 was also defined in <span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span>; a discussion of this
tag number follows in <a href="#encodedtext" class="xref">Section 3.4.5.3</a>.)
Note that many other tag numbers have been defined since the publication of <span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span>;
see the registry described at <a href="#ianatags" class="xref">Section 9.2</a> for the complete list.<a href="#section-3.4-8" class="pilcrow">¶</a></p>
<span id="name-tag-numbers-defined-in-rfc-"></span><div id="tagvalues">
<table class="center" id="table-5">
          <caption>
<a href="#table-5" class="selfRef">Table 5</a>:
<a href="#name-tag-numbers-defined-in-rfc-" class="selfRef">Tag Numbers Defined in RFC 7049</a>
          </caption>
<thead>
            <tr>
              <th class="text-left" rowspan="1" colspan="1">Tag</th>
              <th class="text-left" rowspan="1" colspan="1">Data Item</th>
              <th class="text-left" rowspan="1" colspan="1">Semantics</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">0</td>
              <td class="text-left" rowspan="1" colspan="1">text string</td>
              <td class="text-left" rowspan="1" colspan="1">Standard date/time string; see <a href="#stringdatetimesect" class="xref">Section 3.4.1</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">1</td>
              <td class="text-left" rowspan="1" colspan="1">integer or float</td>
              <td class="text-left" rowspan="1" colspan="1">Epoch-based date/time; see <a href="#epochdatetimesect" class="xref">Section 3.4.2</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">2</td>
              <td class="text-left" rowspan="1" colspan="1">byte string</td>
              <td class="text-left" rowspan="1" colspan="1">Unsigned bignum; see <a href="#bignums" class="xref">Section 3.4.3</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">3</td>
              <td class="text-left" rowspan="1" colspan="1">byte string</td>
              <td class="text-left" rowspan="1" colspan="1">Negative bignum; see <a href="#bignums" class="xref">Section 3.4.3</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">4</td>
              <td class="text-left" rowspan="1" colspan="1">array</td>
              <td class="text-left" rowspan="1" colspan="1">Decimal fraction; see <a href="#fractions" class="xref">Section 3.4.4</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">5</td>
              <td class="text-left" rowspan="1" colspan="1">array</td>
              <td class="text-left" rowspan="1" colspan="1">Bigfloat; see <a href="#fractions" class="xref">Section 3.4.4</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">21</td>
              <td class="text-left" rowspan="1" colspan="1">(any)</td>
              <td class="text-left" rowspan="1" colspan="1">Expected conversion to base64url encoding; see <a href="#convexpect" class="xref">Section 3.4.5.2</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">22</td>
              <td class="text-left" rowspan="1" colspan="1">(any)</td>
              <td class="text-left" rowspan="1" colspan="1">Expected conversion to base64 encoding; see <a href="#convexpect" class="xref">Section 3.4.5.2</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">23</td>
              <td class="text-left" rowspan="1" colspan="1">(any)</td>
              <td class="text-left" rowspan="1" colspan="1">Expected conversion to base16 encoding; see <a href="#convexpect" class="xref">Section 3.4.5.2</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">24</td>
              <td class="text-left" rowspan="1" colspan="1">byte string</td>
              <td class="text-left" rowspan="1" colspan="1">Encoded CBOR data item; see <a href="#embedded-di" class="xref">Section 3.4.5.1</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">32</td>
              <td class="text-left" rowspan="1" colspan="1">text string</td>
              <td class="text-left" rowspan="1" colspan="1">URI; see <a href="#encodedtext" class="xref">Section 3.4.5.3</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">33</td>
              <td class="text-left" rowspan="1" colspan="1">text string</td>
              <td class="text-left" rowspan="1" colspan="1">base64url; see <a href="#encodedtext" class="xref">Section 3.4.5.3</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">34</td>
              <td class="text-left" rowspan="1" colspan="1">text string</td>
              <td class="text-left" rowspan="1" colspan="1">base64; see <a href="#encodedtext" class="xref">Section 3.4.5.3</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">36</td>
              <td class="text-left" rowspan="1" colspan="1">text string</td>
              <td class="text-left" rowspan="1" colspan="1">MIME message; see <a href="#encodedtext" class="xref">Section 3.4.5.3</a>
</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">55799</td>
              <td class="text-left" rowspan="1" colspan="1">(any)</td>
              <td class="text-left" rowspan="1" colspan="1">Self-described CBOR; see <a href="#self-describe" class="xref">Section 3.4.6</a>
</td>
            </tr>
          </tbody>
        </table>
</div>
<p id="section-3.4-10">Conceptually, tags are interpreted in the generic data model, not at
(de-)serialization time.  A small number of tags (at this time, tag
number 25 and tag number 29 <span>[<a href="#IANA.cbor-tags" class="xref">IANA.cbor-tags</a>]</span>) have been registered with semantics that
may require processing at (de-)serialization time: the decoder needs to
be aware of, and the encoder needs to be in control of, the exact
sequence in which data items are encoded into the CBOR data item.
This means these tags cannot be implemented on top of an arbitrary generic
CBOR encoder/decoder (which might not reflect the serialization order
for entries in a map at the data model level and vice versa); their
implementation therefore typically needs to be integrated into the
generic encoder/decoder.  The definition of new tags with this
property is <span class="bcp14">NOT RECOMMENDED</span>.<a href="#section-3.4-10" class="pilcrow">¶</a></p>
<p id="section-3.4-11">IANA allocated tag numbers 65535, 4294967295, and
18446744073709551615 (binary all-ones in 16-bit, 32-bit, and 64-bit).
These can be used as a convenience for implementers
who want a single-integer data structure to indicate either the 
presence of a specific tag or absence of a tag.
That allocation is described in <span><a href="https://tools.ietf.org/html/draft-bormann-cbor-notable-tags-02#section-10" class="relref">Section 10</a> of [<a href="#I-D.bormann-cbor-notable-tags" class="xref">CBOR-TAGS</a>]</span>.
These tags are not intended to occur in actual CBOR data items;
implementations <span class="bcp14">MAY</span> flag such an occurrence as an error.<a href="#section-3.4-11" class="pilcrow">¶</a></p>
<p id="section-3.4-12">Protocols can extend the generic data model (<a href="#cbor-data-models" class="xref">Section 2</a>) with data 
   items representing points in time by using tag numbers 0 and 1, with 
   arbitrarily sized integers by using tag numbers 2 and 3, and with 
   floating-point values of arbitrary size and precision by using tag 
   numbers 4 and 5.<a href="#section-3.4-12" class="pilcrow">¶</a></p>
<div id="stringdatetimesect">
<section id="section-3.4.1">
          <h4 id="name-standard-date-time-string">
<a href="#section-3.4.1" class="section-number selfRef">3.4.1. </a><a href="#name-standard-date-time-string" class="section-name selfRef">Standard Date/Time String</a>
          </h4>
<p id="section-3.4.1-1">Tag number 0 contains a text string in the standard format described by
the <code>date-time</code> production in <span>[<a href="#RFC3339" class="xref">RFC3339</a>]</span>, as refined by 
<span><a href="https://www.rfc-editor.org/rfc/rfc4287#section-3.3" class="relref">Section 3.3</a> of [<a href="#RFC4287" class="xref">RFC4287</a>]</span>, representing the point in time described there. A
nested item of another type or a text string that doesn't match the 
format described in <span>[<a href="#RFC4287" class="xref">RFC4287</a>]</span> is invalid.<a href="#section-3.4.1-1" class="pilcrow">¶</a></p>
</section>
</div>
<div id="epochdatetimesect">
<section id="section-3.4.2">
          <h4 id="name-epoch-based-date-time">
<a href="#section-3.4.2" class="section-number selfRef">3.4.2. </a><a href="#name-epoch-based-date-time" class="section-name selfRef">Epoch-Based Date/Time</a>
          </h4>
<p id="section-3.4.2-1">Tag number 1 contains a numerical value counting the number of seconds
from 1970-01-01T00:00Z in UTC time to the represented point in civil
time.<a href="#section-3.4.2-1" class="pilcrow">¶</a></p>
<p id="section-3.4.2-2">The tag content <span class="bcp14">MUST</span> be an unsigned or negative integer (major types 0
and 1) or a floating-point number (major type 7 with additional
information 25, 26, or 27). Other contained types are invalid.<a href="#section-3.4.2-2" class="pilcrow">¶</a></p>
<p id="section-3.4.2-3">Nonnegative values (major type 0 and nonnegative floating-point
numbers) stand for time values on or after 1970-01-01T00:00Z UTC and
are interpreted according to POSIX <span>[<a href="#TIME_T" class="xref">TIME_T</a>]</span>.
(POSIX time is also known as "UNIX Epoch time".)
Leap seconds
are handled specially by POSIX time, and this results in a 1-second
discontinuity several times per decade.
Note that applications that require the expression of times beyond
early 2106 cannot leave out support of 64-bit integers for the tag content.<a href="#section-3.4.2-3" class="pilcrow">¶</a></p>
<p id="section-3.4.2-4">Negative values (major type 1 and negative floating-point numbers) are
interpreted as determined by the application requirements as there is
no universal standard for UTC count-of-seconds time before
1970-01-01T00:00Z (this is particularly true for points in time that
precede discontinuities in national calendars).  The same applies to
non-finite values.<a href="#section-3.4.2-4" class="pilcrow">¶</a></p>
<p id="section-3.4.2-5">To indicate fractional seconds, floating-point values can be used
within tag number 1 instead of integer values.  Note that this generally
requires binary64 support, as binary16 and binary32 provide nonzero
fractions of seconds only for a short period of time around
early 1970.  An application that requires tag number 1 support may restrict
the tag content to be an integer (or a floating-point value) only.<a href="#section-3.4.2-5" class="pilcrow">¶</a></p>
<p id="section-3.4.2-6">Note that platform types for date/time may include <code>null</code> or <code>undefined</code>
values, which may also be desirable at an application protocol level.
While emitting tag number 1 values with non-finite tag content values
(e.g., with NaN for undefined date/time values or with Infinity for an
expiry date that is not set) may seem an obvious way to handle this,
using untagged <code>null</code> or <code>undefined</code> avoids the use of non-finites and results in a shorter encoding.
Application protocol designers are encouraged to consider these cases
and include clear guidelines for handling them.<a href="#section-3.4.2-6" class="pilcrow">¶</a></p>
</section>
</div>
<div id="bignums">
<section id="section-3.4.3">
          <h4 id="name-bignums">
<a href="#section-3.4.3" class="section-number selfRef">3.4.3. </a><a href="#name-bignums" class="section-name selfRef">Bignums</a>
          </h4>
<p id="section-3.4.3-1">Protocols using tag numbers 2 and 3 extend the generic data model
(<a href="#cbor-data-models" class="xref">Section 2</a>) with "bignums" representing arbitrarily sized
integers. In the basic generic data model, bignum values are not equal
to integers from the same model, but the extended generic data model
created by this tag definition defines equivalence based on numeric
value, and preferred serialization (<a href="#preferred" class="xref">Section 4.1</a>) never makes use of
bignums that also can be expressed as basic integers (see below).<a href="#section-3.4.3-1" class="pilcrow">¶</a></p>
<p id="section-3.4.3-2">Bignums are encoded as a byte string data item, which is interpreted
as an unsigned integer n in network byte order.  Contained items of
other types are invalid.  For tag number 2, the
value of the bignum is n.  For tag number 3, the value of the bignum is
-1 - n.  The preferred serialization of the byte string is to leave out any
leading zeroes (note that this means the preferred serialization for n = 0
is the empty byte string, but see below).
Decoders that understand these tags <span class="bcp14">MUST</span> be able to decode
bignums that do have leading zeroes.
The preferred serialization of an integer that can be represented using
major type 0 or 1 is to encode it this way instead of as a bignum
(which means that the empty string never occurs in a bignum when using
preferred serialization).
Note that this means the non-preferred choice of a bignum
representation instead of a basic integer for encoding a number is not
intended to have application semantics (just as the choice of a longer
basic integer representation than needed, such as 0x1800 for 0x00, does
not).<a href="#section-3.4.3-2" class="pilcrow">¶</a></p>
<p id="section-3.4.3-3">For example, the number 18446744073709551616 (2<sup>64</sup>) is represented
as 0b110_00010 (major type 6, tag number 2), followed by 0b010_01001 (major
type 2, length 9), followed by 0x010000000000000000 (one byte 0x01 and
eight bytes 0x00). In hexadecimal:<a href="#section-3.4.3-3" class="pilcrow">¶</a></p>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.4.3-4">
<pre>
C2                        -- Tag 2
   49                     -- Byte string of length 9
      010000000000000000  -- Bytes content
</pre><a href="#section-3.4.3-4" class="pilcrow">¶</a>
</div>
</section>
</div>
<div id="fractions">
<section id="section-3.4.4">
          <h4 id="name-decimal-fractions-and-bigfl">
<a href="#section-3.4.4" class="section-number selfRef">3.4.4. </a><a href="#name-decimal-fractions-and-bigfl" class="section-name selfRef">Decimal Fractions and Bigfloats</a>
          </h4>
<p id="section-3.4.4-1">Protocols using tag number 4 extend the generic data model with data
items representing arbitrary-length decimal fractions of the form m*(10<sup>e</sup>).
Protocols using tag number 5 extend the generic data model with data
items representing arbitrary-length binary fractions of the form m*(2<sup>e</sup>).
As with
bignums, values of different types are not equal in the generic data
model.<a href="#section-3.4.4-1" class="pilcrow">¶</a></p>
<p id="section-3.4.4-2">Decimal fractions combine an integer mantissa with a base-10 scaling
factor.  They are most useful if an application needs the exact
representation of a decimal fraction such as 1.1 because there is no
exact representation for many decimal fractions in binary
floating-point representations.<a href="#section-3.4.4-2" class="pilcrow">¶</a></p>
<p id="section-3.4.4-3">"Bigfloats" combine an integer mantissa with a base-2 scaling factor.
They are binary floating-point values that can exceed the range or the
precision of the three IEEE 754 formats supported by CBOR
(<a href="#fpnocont" class="xref">Section 3.3</a>).  Bigfloats may also be used by constrained
applications that need some basic binary floating-point capability
without the need for supporting IEEE 754.<a href="#section-3.4.4-3" class="pilcrow">¶</a></p>
<p id="section-3.4.4-4">A decimal fraction or a bigfloat is represented as a tagged array that
contains exactly two integer numbers: an exponent e and a mantissa m.
Decimal fractions (tag number 4) use base-10 exponents; the value of a
decimal fraction data item is m*(10<sup>e</sup>).  Bigfloats (tag number 5) use
base-2 exponents; the value of a bigfloat data item is m*(2<sup>e</sup>).
The exponent e <span class="bcp14">MUST</span> be represented in an integer of major type 0 or 1,
while the mantissa can also be a bignum (<a href="#bignums" class="xref">Section 3.4.3</a>).  Contained
items with other structures are invalid.<a href="#section-3.4.4-4" class="pilcrow">¶</a></p>
<p id="section-3.4.4-5">An example of a decimal fraction is the representation of the number 273.15 
as 0b110_00100 (major type 6 for tag, additional
information 4 for the tag number), followed by 0b100_00010 (major
type 4 for the array, additional information 2 for the length of
the array), followed by 0b001_00001 (major type 1 for the first
integer, additional information 1 for the value of -2), followed by
0b000_11001 (major type 0 for the second integer, additional
information 25 for a two-byte value), followed by
0b0110101010110011 (27315 in two bytes).  In hexadecimal:<a href="#section-3.4.4-5" class="pilcrow">¶</a></p>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.4.4-6">
<pre>
C4             -- Tag 4
   82          -- Array of length 2
      21       -- -2
      19 6ab3  -- 27315
</pre><a href="#section-3.4.4-6" class="pilcrow">¶</a>
</div>
<p id="section-3.4.4-7">An example of a bigfloat is the representation of the number 1.5 
as 0b110_00101 (major type 6 for tag, additional information
5 for the tag number), followed by 0b100_00010 (major type 4 for
the array, additional information 2 for the length of the array),
followed by 0b001_00000 (major type 1 for the first integer,
additional information 0 for the value of -1), followed by
0b000_00011 (major type 0 for the second integer, additional
information 3 for the value of 3).  In hexadecimal:<a href="#section-3.4.4-7" class="pilcrow">¶</a></p>
<div class="artwork art-text alignLeft art-hex-dump" id="section-3.4.4-8">
<pre>
C5             -- Tag 5
   82          -- Array of length 2
      20       -- -1
      03       -- 3
</pre><a href="#section-3.4.4-8" class="pilcrow">¶</a>
</div>
<p id="section-3.4.4-9">Decimal fractions and bigfloats provide no representation of Infinity,
-Infinity, or NaN; if these are needed in place of a decimal fraction
or bigfloat, the IEEE 754 half-precision representations from
<a href="#fpnocont" class="xref">Section 3.3</a> can be used.<a href="#section-3.4.4-9" class="pilcrow">¶</a></p>
</section>
</div>
<div id="content-hints">
<section id="section-3.4.5">
          <h4 id="name-content-hints">
<a href="#section-3.4.5" class="section-number selfRef">3.4.5. </a><a href="#name-content-hints" class="section-name selfRef">Content Hints</a>
          </h4>
<p id="section-3.4.5-1">The tags in this section are for content hints that might be used by
generic CBOR processors. These content hints do not extend the generic
data model.<a href="#section-3.4.5-1" class="pilcrow">¶</a></p>
<div id="embedded-di">
<section id="section-3.4.5.1">
            <h5 id="name-encoded-cbor-data-item">
<a href="#section-3.4.5.1" class="section-number selfRef">3.4.5.1. </a><a href="#name-encoded-cbor-data-item" class="section-name selfRef">Encoded CBOR Data Item</a>
            </h5>
<p id="section-3.4.5.1-1">Sometimes it is beneficial to carry an embedded CBOR data item that is
not meant to be decoded immediately at the time the enclosing data
item is being decoded.  Tag number 24 (CBOR data item) can be used to tag the
embedded byte string as a single data item encoded in CBOR format.  Contained
items that aren't byte strings are invalid.  A contained byte string
is valid if it encodes a well-formed CBOR data item; validity checking of
the decoded CBOR item is not required for tag validity (but could be
offered by a generic decoder as a special option).<a href="#section-3.4.5.1-1" class="pilcrow">¶</a></p>
</section>
</div>
<div id="convexpect">
<section id="section-3.4.5.2">
            <h5 id="name-expected-later-encoding-for">
<a href="#section-3.4.5.2" class="section-number selfRef">3.4.5.2. </a><a href="#name-expected-later-encoding-for" class="section-name selfRef">Expected Later Encoding for CBOR-to-JSON Converters</a>
            </h5>
<p id="section-3.4.5.2-1">Tag numbers 21 to 23 indicate that a byte string might require a specific
encoding when interoperating with a text-based representation.  These
tags are useful when an encoder knows that the byte string data it is
writing is likely to be later converted to a particular JSON-based
usage. That usage specifies that some strings are encoded as base64,
base64url, and so on. The encoder uses byte strings instead of doing
the encoding itself to reduce the message size, to reduce the code
size of the encoder, or both.  The encoder does not know whether or
not the converter will be generic, and therefore wants to say what it
believes is the proper way to convert binary strings to JSON.<a href="#section-3.4.5.2-1" class="pilcrow">¶</a></p>
<p id="section-3.4.5.2-2">The data item tagged can be a byte string or any other data item.  In
the latter case, the tag applies to all of the byte string data items
contained in the data item, except for those contained in a nested
data item tagged with an expected conversion.<a href="#section-3.4.5.2-2" class="pilcrow">¶</a></p>
<p id="section-3.4.5.2-3">These three tag numbers suggest conversions to three of 
the base data encodings defined in <span>[<a href="#RFC4648" class="xref">RFC4648</a>]</span>.   
Tag number 21 suggests conversion to base64url encoding 
(<span><a href="https://www.rfc-editor.org/rfc/rfc4648#section-5" class="relref">Section 5</a> of [<a href="#RFC4648" class="xref">RFC4648</a>]</span>) 
where padding is not used (see 
<span><a href="https://www.rfc-editor.org/rfc/rfc4648#section-3.2" class="relref">Section 3.2</a> of [<a href="#RFC4648" class="xref">RFC4648</a>]</span>); 
that is, all trailing equals signs ("=") are removed from the encoded string.
Tag number 22 suggests conversion to classical base64 encoding 
(<span><a href="https://www.rfc-editor.org/rfc/rfc4648#section-4" class="relref">Section 4</a> of [<a href="#RFC4648" class="xref">RFC4648</a>]</span>) 
with padding as defined in RFC 4648.
For both base64url and base64, padding bits are set to zero (see
<span><a href="https://www.rfc-editor.org/rfc/rfc4648#section-3.5" class="relref">Section 3.5</a> of [<a href="#RFC4648" class="xref">RFC4648</a>]</span>), 
and the conversion to alternate encoding
is performed on the contents of the byte string (that is, without adding any line breaks, whitespace, or
other additional characters).  Tag number 23 suggests conversion to
base16 (hex) encoding with uppercase alphabetics (see 
<span><a href="https://www.rfc-editor.org/rfc/rfc4648#section-8" class="relref">Section 8</a> of [<a href="#RFC4648" class="xref">RFC4648</a>]</span>).
Note that, for all three tag numbers, the
encoding of the empty byte string is the empty text string.<a href="#section-3.4.5.2-3" class="pilcrow">¶</a></p>
</section>
</div>
<div id="encodedtext">
<section id="section-3.4.5.3">
            <h5 id="name-encoded-text">
<a href="#section-3.4.5.3" class="section-number selfRef">3.4.5.3. </a><a href="#name-encoded-text" class="section-name selfRef">Encoded Text</a>
            </h5>
<p id="section-3.4.5.3-1">Some text strings hold data that have formats widely used on the
Internet, and sometimes those formats can be validated and presented
to the application in appropriate form by the decoder. There are tags
for some of these formats.<a href="#section-3.4.5.3-1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-3.4.5.3-2.1">Tag number 32 is for URIs, as defined in <span>[<a href="#RFC3986" class="xref">RFC3986</a>]</span>.  If the text string
doesn't match the <code>URI-reference</code> production, the string is invalid.<a href="#section-3.4.5.3-2.1" class="pilcrow">¶</a>
</li>
              <li class="normal" id="section-3.4.5.3-2.2">
                <p id="section-3.4.5.3-2.2.1">Tag numbers 33 and 34 are for base64url- and base64-encoded text
strings, respectively,
as defined in <span>[<a href="#RFC4648" class="xref">RFC4648</a>]</span>.  If any of the following apply:<a href="#section-3.4.5.3-2.2.1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-3.4.5.3-2.2.2.1">the encoded text string contains non-alphabet characters or only 1
alphabet character in the last block of 4 (where alphabet is
defined by <span><a href="https://www.rfc-editor.org/rfc/rfc4648#section-5" class="relref">Section 5</a> of [<a href="#RFC4648" class="xref">RFC4648</a>]</span> for tag number 33 and 
<span><a href="https://www.rfc-editor.org/rfc/rfc4648#section-4" class="relref">Section 4</a> of [<a href="#RFC4648" class="xref">RFC4648</a>]</span> for tag number 34), or<a href="#section-3.4.5.3-2.2.2.1" class="pilcrow">¶</a>
</li>
                  <li class="normal" id="section-3.4.5.3-2.2.2.2">the padding bits in a 2- or 3-character block are not 0, or<a href="#section-3.4.5.3-2.2.2.2" class="pilcrow">¶</a>
</li>
                  <li class="normal" id="section-3.4.5.3-2.2.2.3">the base64 encoding has the wrong number of padding characters, or<a href="#section-3.4.5.3-2.2.2.3" class="pilcrow">¶</a>
</li>
                  <li class="normal" id="section-3.4.5.3-2.2.2.4">the base64url encoding has padding characters,<a href="#section-3.4.5.3-2.2.2.4" class="pilcrow">¶</a>
</li>
                </ul>
<p id="section-3.4.5.3-2.2.3">
the string is invalid.<a href="#section-3.4.5.3-2.2.3" class="pilcrow">¶</a></p>
</li>
              <li class="normal" id="section-3.4.5.3-2.3">Tag number 36 is for MIME messages (including all headers), as defined in
<span>[<a href="#RFC2045" class="xref">RFC2045</a>]</span>. A text string that isn't a valid MIME message is
invalid.  (For this tag, validity checking
may be particularly onerous for a generic decoder and might
therefore not be offered.  Note that many MIME messages are general
binary data and therefore cannot be represented in a text string;
<span>[<a href="#IANA.cbor-tags" class="xref">IANA.cbor-tags</a>]</span> lists a registration for tag number 257 that is
similar to tag number 36 but uses a byte string as its tag content.)<a href="#section-3.4.5.3-2.3" class="pilcrow">¶</a>
</li>
            </ul>
<p id="section-3.4.5.3-3">Note that tag numbers 33 and 34 differ from 21 and 22 in that the data is
transported in base-encoded form for the former and in raw byte string
form for the latter.<a href="#section-3.4.5.3-3" class="pilcrow">¶</a></p>
<p id="section-3.4.5.3-4"><span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span> also defined a tag number 35 for regular expressions that
are in Perl Compatible Regular Expressions (PCRE/PCRE2) form <span>[<a href="#PCRE" class="xref">PCRE</a>]</span>
or in JavaScript regular expression syntax <span>[<a href="#ECMA262" class="xref">ECMA262</a>]</span>.
The state of the art in these regular expression specifications has
since advanced and is continually advancing, so this 
specification does not attempt to update the references.
Instead, this tag remains available (as registered in <span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span>) for
applications that specify the particular regular expression variant
they use out-of-band (possibly by limiting the usage to a defined
common subset of both PCRE and ECMA262).
As this specification clarifies tag validity beyond
<span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span>, we note that due to the open way the tag was defined in
<span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span>, any contained string value needs to be valid at the CBOR
tag level (but then may not be "expected" at the application level).<a href="#section-3.4.5.3-4" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
<div id="self-describe">
<section id="section-3.4.6">
          <h4 id="name-self-described-cbor">
<a href="#section-3.4.6" class="section-number selfRef">3.4.6. </a><a href="#name-self-described-cbor" class="section-name selfRef">Self-Described CBOR</a>
          </h4>
<p id="section-3.4.6-1">In many applications, it will be clear from the context that CBOR is
being employed for encoding a data item.  For instance, a specific
protocol might specify the use of CBOR, or a media type is indicated
that specifies its use.  However, there may be applications where such
context information is not available, such as when CBOR data is stored
in a file that does not have disambiguating metadata.  Here, it may
help to have some distinguishing characteristics for the data itself.<a href="#section-3.4.6-1" class="pilcrow">¶</a></p>
<p id="section-3.4.6-2">Tag number 55799 is defined for this purpose, specifically for use at
the start of a stored encoded CBOR data item as specified by an application.
It does not impart any special
semantics on the data item that it encloses; that is, the semantics of
the tag content enclosed in tag number 55799 is exactly identical to the semantics
of the tag content itself.<a href="#section-3.4.6-2" class="pilcrow">¶</a></p>
<p id="section-3.4.6-3">The serialization of this tag's head is 0xd9d9f7, which does not appear to be in
use as a distinguishing mark for any frequently used file types.  In
particular, 0xd9d9f7 is not a valid start of a Unicode text in any Unicode
encoding if it is followed by a valid CBOR data item.<a href="#section-3.4.6-3" class="pilcrow">¶</a></p>
<p id="section-3.4.6-4">For instance, a decoder might be able to decode both CBOR and
JSON. Such a decoder would need to mechanically distinguish the two
formats. An easy way for an encoder to help the decoder would be to
tag the entire CBOR item with tag number 55799, the serialization of which
will never be found at the beginning of a JSON text.<a href="#section-3.4.6-4" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
</section>
</div>
<div id="serialization-considerations">
<section id="section-4">
      <h2 id="name-serialization-consideration">
<a href="#section-4" class="section-number selfRef">4. </a><a href="#name-serialization-consideration" class="section-name selfRef">Serialization Considerations</a>
      </h2>
<div id="preferred">
<section id="section-4.1">
        <h3 id="name-preferred-serialization">
<a href="#section-4.1" class="section-number selfRef">4.1. </a><a href="#name-preferred-serialization" class="section-name selfRef">Preferred Serialization</a>
        </h3>
<p id="section-4.1-1">For some values at the data model level, CBOR provides multiple
serializations.
For many applications, it is desirable that an encoder always chooses
a preferred serialization (preferred encoding); however, the present specification does not
put the burden of enforcing this preference on either the encoder or decoder.<a href="#section-4.1-1" class="pilcrow">¶</a></p>
<p id="section-4.1-2">Some constrained decoders may be limited in their ability to decode
        non-preferred serializations: for example, if only integers below
        1_000_000_000 (one billion) are expected in an application, the
        decoder may leave out the code that would be needed to decode 64-bit
        arguments in integers.  An encoder that always uses preferred
        serialization ("preferred encoder") interoperates with this decoder
        for the numbers that can occur in this application.  Generally
        speaking, a preferred encoder is more universally interoperable (and
        also less wasteful) than one that, say, always uses 64-bit
        integers.<a href="#section-4.1-2" class="pilcrow">¶</a></p>
<p id="section-4.1-3">Similarly, a constrained encoder may be limited in the variety of
representation variants it supports such that it does not
emit preferred serializations ("variant encoder"). For instance, a constrained encoder could
be designed to
always use the 32-bit variant for an integer that it encodes even if a
short representation is available (assuming that there is no application need for integers that can only
be represented with the 64-bit variant).
A decoder that does not rely on 
receiving only preferred serializations ("variation-tolerant decoder") can therefore be said to be more
universally interoperable (it might very well optimize for the case of
receiving preferred serializations, though).
Full implementations of CBOR decoders are by definition
variation tolerant; the distinction is only relevant if a constrained
implementation of a CBOR decoder meets a variant encoder.<a href="#section-4.1-3" class="pilcrow">¶</a></p>
<p id="section-4.1-4">The preferred serialization always uses the shortest form of
representing the argument (<a href="#encoding" class="xref">Section 3</a>); it also uses the shortest
floating-point encoding that preserves the value being encoded.<a href="#section-4.1-4" class="pilcrow">¶</a></p>
<p id="section-4.1-5">The preferred serialization for a floating-point value is the shortest
floating-point encoding that preserves its value, e.g., 0xf94580 for
the number 5.5, and 0xfa45ad9c00 for the number 5555.5.  For NaN
values, a shorter encoding is preferred if zero-padding the shorter
significand towards the right reconstitutes the original NaN value
(for many applications, the single NaN encoding 0xf97e00 will
suffice).<a href="#section-4.1-5" class="pilcrow">¶</a></p>
<p id="section-4.1-6">Definite-length encoding is preferred whenever the length is known at
the time the serialization of the item starts.<a href="#section-4.1-6" class="pilcrow">¶</a></p>
</section>
</div>
<div id="det-enc">
<section id="section-4.2">
        <h3 id="name-deterministically-encoded-c">
<a href="#section-4.2" class="section-number selfRef">4.2. </a><a href="#name-deterministically-encoded-c" class="section-name selfRef">Deterministically Encoded CBOR</a>
        </h3>
<p id="section-4.2-1">Some protocols may want encoders to only emit CBOR in a particular
deterministic format; those protocols might also have the decoders check
that their input is in that deterministic format. Those protocols are
free to define what
they mean by a "deterministic format" and what encoders and decoders are
expected to do. This section defines a set of restrictions that can
serve as the base of such a deterministic format.<a href="#section-4.2-1" class="pilcrow">¶</a></p>
<div id="core-det">
<section id="section-4.2.1">
          <h4 id="name-core-deterministic-encoding">
<a href="#section-4.2.1" class="section-number selfRef">4.2.1. </a><a href="#name-core-deterministic-encoding" class="section-name selfRef">Core Deterministic Encoding Requirements</a>
          </h4>
<p id="section-4.2.1-1">A CBOR encoding satisfies the "core deterministic encoding requirements" if
it satisfies the following restrictions:<a href="#section-4.2.1-1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-4.2.1-2.1">
              <p id="section-4.2.1-2.1.1">Preferred serialization <span class="bcp14">MUST</span> be used.  In particular, this means
that arguments (see <a href="#encoding" class="xref">Section 3</a>) for integers, lengths in major types
2 through 5, and tags <span class="bcp14">MUST</span> be as short as possible, for instance:<a href="#section-4.2.1-2.1.1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-4.2.1-2.1.2.1">0 to 23 and -1 to -24 <span class="bcp14">MUST</span> be expressed in the same byte as the
major type;<a href="#section-4.2.1-2.1.2.1" class="pilcrow">¶</a>
</li>
                <li class="normal" id="section-4.2.1-2.1.2.2">24 to 255 and -25 to -256 <span class="bcp14">MUST</span> be expressed only with an
additional uint8_t;<a href="#section-4.2.1-2.1.2.2" class="pilcrow">¶</a>
</li>
                <li class="normal" id="section-4.2.1-2.1.2.3">256 to 65535 and -257 to -65536 <span class="bcp14">MUST</span> be expressed only with an
additional uint16_t;<a href="#section-4.2.1-2.1.2.3" class="pilcrow">¶</a>
</li>
                <li class="normal" id="section-4.2.1-2.1.2.4">65536 to 4294967295 and -65537 to -4294967296 <span class="bcp14">MUST</span> be expressed
only with an additional uint32_t.<a href="#section-4.2.1-2.1.2.4" class="pilcrow">¶</a>
</li>
              </ul>
<p id="section-4.2.1-2.1.3">
Floating-point values also <span class="bcp14">MUST</span> use the shortest form that preserves
the value, e.g., 1.5 is encoded as 0xf93e00 (binary16) and 1000000.5 as
0xfa49742408 (binary32).
(One implementation of this is to have all floats start as a 64-bit
float, then do a test conversion to a 32-bit float; if the result is
the same numeric value, use the shorter form and repeat the process
with a test conversion to a 16-bit float.  This also works to select
16-bit float for positive and negative Infinity as well.)<a href="#section-4.2.1-2.1.3" class="pilcrow">¶</a></p>
</li>
            <li class="normal" id="section-4.2.1-2.2">Indefinite-length items <span class="bcp14">MUST NOT</span> appear. They can be encoded as
definite-length items instead.<a href="#section-4.2.1-2.2" class="pilcrow">¶</a>
</li>
            <li class="normal" id="section-4.2.1-2.3">
              <p id="section-4.2.1-2.3.1">The keys in every map <span class="bcp14">MUST</span> be sorted in the
              bytewise lexicographic order of their deterministic
              encodings. For example, the following keys are sorted correctly:<a href="#section-4.2.1-2.3.1" class="pilcrow">¶</a></p>
<ol start="1" type="1" class="normal type-1" id="section-4.2.1-2.3.2">
<li id="section-4.2.1-2.3.2.1">10, encoded as 0x0a.<a href="#section-4.2.1-2.3.2.1" class="pilcrow">¶</a>
</li>
                <li id="section-4.2.1-2.3.2.2">100, encoded as 0x1864.<a href="#section-4.2.1-2.3.2.2" class="pilcrow">¶</a>
</li>
                <li id="section-4.2.1-2.3.2.3">-1, encoded as 0x20.<a href="#section-4.2.1-2.3.2.3" class="pilcrow">¶</a>
</li>
                <li id="section-4.2.1-2.3.2.4">"z", encoded as 0x617a.<a href="#section-4.2.1-2.3.2.4" class="pilcrow">¶</a>
</li>
                <li id="section-4.2.1-2.3.2.5">"aa", encoded as 0x626161.<a href="#section-4.2.1-2.3.2.5" class="pilcrow">¶</a>
</li>
                <li id="section-4.2.1-2.3.2.6">[100], encoded as 0x811864.<a href="#section-4.2.1-2.3.2.6" class="pilcrow">¶</a>
</li>
                <li id="section-4.2.1-2.3.2.7">[-1], encoded as 0x8120.<a href="#section-4.2.1-2.3.2.7" class="pilcrow">¶</a>
</li>
                <li id="section-4.2.1-2.3.2.8">false, encoded as 0xf4.<a href="#section-4.2.1-2.3.2.8" class="pilcrow">¶</a>
</li>
              </ol>
</li>
          </ul>
<aside id="section-4.2.1-3">
            <p id="section-4.2.1-3.1">
Implementation note: the self-delimiting nature of the CBOR
encoding means that there are no two well-formed CBOR encoded data
items where one is a prefix of the other.
The bytewise lexicographic comparison of deterministic encodings of
different map keys therefore always ends in a position where the
byte differs between the keys, before the end of a key is reached.<a href="#section-4.2.1-3.1" class="pilcrow">¶</a></p>
</aside>
</section>
</div>
<div id="additional-deterministic-encoding-considerations">
<section id="section-4.2.2">
          <h4 id="name-additional-deterministic-en">
<a href="#section-4.2.2" class="section-number selfRef">4.2.2. </a><a href="#name-additional-deterministic-en" class="section-name selfRef">Additional Deterministic Encoding Considerations</a>
          </h4>
<p id="section-4.2.2-1">CBOR tags present additional considerations for deterministic
encoding.  If a CBOR-based protocol were to provide the same semantics
for the presence and absence of a specific tag (e.g., by allowing both
tag 1 data items and raw numbers in a date/time position, treating the
latter as if they were tagged), the deterministic format would not
allow the presence of the tag, based on the "shortest form" principle.
For example, a protocol might give encoders the choice of representing a URL as
either a text string or, using <a href="#encodedtext" class="xref">Section 3.4.5.3</a>, tag number 32 containing a
text string. This protocol's deterministic encoding needs either to
require that the tag is present or to require that it is absent, not
allow either one.<a href="#section-4.2.2-1" class="pilcrow">¶</a></p>
<p id="section-4.2.2-2">In a protocol that does require tags in certain places to
obtain specific semantics, the tag needs to appear in the
deterministic format as well.  Deterministic encoding considerations
also apply to the content of tags.<a href="#section-4.2.2-2" class="pilcrow">¶</a></p>
<p id="section-4.2.2-3">If a protocol includes a field that can express integers with an
absolute value of 2<sup>64</sup> or larger using tag numbers 2 or 3
(<a href="#bignums" class="xref">Section 3.4.3</a>), the protocol's deterministic encoding needs to specify
whether smaller integers are also expressed using these tags or using
major types 0 and 1.  Preferred serialization uses the latter choice,
which is therefore recommended.<a href="#section-4.2.2-3" class="pilcrow">¶</a></p>
<p id="section-4.2.2-4">Protocols that include floating-point values, whether represented
using basic floating-point values (<a href="#fpnocont" class="xref">Section 3.3</a>) or using tags (or
both), may need to define extra requirements on their deterministic
encodings, such as:<a href="#section-4.2.2-4" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-4.2.2-5.1">Although IEEE floating-point values can represent both positive and negative zero as
distinct values, the application might not distinguish these and might
decide to represent all zero values with a positive sign, disallowing
negative zero.
(The application may also want to restrict the precision of
floating-point values in such a way that there is never a need to represent
64-bit -- or even 32-bit -- floating-point values.)<a href="#section-4.2.2-5.1" class="pilcrow">¶</a>
</li>
            <li class="normal" id="section-4.2.2-5.2">
              <p id="section-4.2.2-5.2.1">If a protocol includes a field that can express floating-point values,
with a specific data model that declares integer and
floating-point values to be interchangeable, the protocol's
deterministic encoding needs to specify
whether, for example, the integer 1.0 is encoded as 0x01 (unsigned
integer), 0xf93c00 (binary16), 0xfa3f800000 (binary32),
or 0xfb3ff0000000000000 (binary64). Example rules for this are:<a href="#section-4.2.2-5.2.1" class="pilcrow">¶</a></p>
<ol start="1" type="1" class="normal type-1" id="section-4.2.2-5.2.2">
<li id="section-4.2.2-5.2.2.1">Encode integral values that fit in 64 bits as values from major
types 0 and 1, and other values as the preferred (smallest of 16-, 32-, or
64-bit) floating-point representation that accurately represents the value,<a href="#section-4.2.2-5.2.2.1" class="pilcrow">¶</a>
</li>
                <li id="section-4.2.2-5.2.2.2">Encode all values as the preferred
floating-point representation that accurately represents the
value, even for integral values, or<a href="#section-4.2.2-5.2.2.2" class="pilcrow">¶</a>
</li>
                <li id="section-4.2.2-5.2.2.3">Encode all values as 64-bit floating-point representations.<a href="#section-4.2.2-5.2.2.3" class="pilcrow">¶</a>
</li>
              </ol>
<p id="section-4.2.2-5.2.3">
Rule 1 straddles the boundaries between integers and floating-point
values, and Rule 3 does not use preferred serialization, so Rule 2 may be
a good choice in many cases.<a href="#section-4.2.2-5.2.3" class="pilcrow">¶</a></p>
</li>
            <li class="normal" id="section-4.2.2-5.3">If NaN is an allowed value, and there is no intent to support NaN
payloads or signaling NaNs, the protocol needs to pick a single
representation, typically 0xf97e00.  If that simple choice is not
possible, specific attention will be needed for NaN handling.<a href="#section-4.2.2-5.3" class="pilcrow">¶</a>
</li>
            <li class="normal" id="section-4.2.2-5.4">Subnormal numbers (nonzero numbers with the lowest possible exponent
of a given IEEE 754 number format) may be flushed to zero outputs or
be treated as zero inputs in some floating-point implementations.
A protocol's deterministic encoding may want to specifically
accommodate such implementations while creating an onus on other
implementations by excluding subnormal numbers from interchange,
interchanging zero instead.<a href="#section-4.2.2-5.4" class="pilcrow">¶</a>
</li>
            <li class="normal" id="section-4.2.2-5.5">The same number can be represented by different decimal fractions,
by different bigfloats, and by different forms under other tags that
may be defined to express numeric values. Depending on the
implementation, it may not always be practical to determine whether
any of these forms (or forms in the basic generic data model) are
equivalent.  An application protocol that presents choices of this
kind for the representation format of numbers needs to be explicit
about how the formats for deterministic encoding are to be chosen.<a href="#section-4.2.2-5.5" class="pilcrow">¶</a>
</li>
          </ul>
</section>
</div>
<div id="length-first">
<section id="section-4.2.3">
          <h4 id="name-length-first-map-key-orderi">
<a href="#section-4.2.3" class="section-number selfRef">4.2.3. </a><a href="#name-length-first-map-key-orderi" class="section-name selfRef">Length-First Map Key Ordering</a>
          </h4>
<p id="section-4.2.3-1">The core deterministic encoding requirements (<a href="#core-det" class="xref">Section 4.2.1</a>) sort map keys in a different
order from the one suggested by <span><a href="https://www.rfc-editor.org/rfc/rfc7049#section-3.9" class="relref">Section 3.9</a> of [<a href="#RFC7049" class="xref">RFC7049</a>]</span> (called
"Canonical CBOR" there). Protocols that need to
be compatible with the order specified in <span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span> can instead be specified in
terms of this specification's "length-first core deterministic encoding
requirements":<a href="#section-4.2.3-1" class="pilcrow">¶</a></p>
<p id="section-4.2.3-2">A CBOR encoding satisfies the "length-first core deterministic encoding
requirements" if it satisfies the core deterministic encoding requirements
except that the keys in every map <span class="bcp14">MUST</span> be sorted such that:<a href="#section-4.2.3-2" class="pilcrow">¶</a></p>
<ol start="1" type="1" class="normal type-1" id="section-4.2.3-3">
<li id="section-4.2.3-3.1">If two keys have different lengths, the shorter one sorts earlier;<a href="#section-4.2.3-3.1" class="pilcrow">¶</a>
</li>
            <li id="section-4.2.3-3.2">If two keys have the same length, the one with the lower value in
(bytewise) lexical order sorts earlier.<a href="#section-4.2.3-3.2" class="pilcrow">¶</a>
</li>
          </ol>
<p id="section-4.2.3-4">For example, under the length-first core deterministic encoding
requirements, the following keys are sorted correctly:<a href="#section-4.2.3-4" class="pilcrow">¶</a></p>
<ol start="1" type="1" class="normal type-1" id="section-4.2.3-5">
<li id="section-4.2.3-5.1">10, encoded as 0x0a.<a href="#section-4.2.3-5.1" class="pilcrow">¶</a>
</li>
            <li id="section-4.2.3-5.2">-1, encoded as 0x20.<a href="#section-4.2.3-5.2" class="pilcrow">¶</a>
</li>
            <li id="section-4.2.3-5.3">false, encoded as 0xf4.<a href="#section-4.2.3-5.3" class="pilcrow">¶</a>
</li>
            <li id="section-4.2.3-5.4">100, encoded as 0x1864.<a href="#section-4.2.3-5.4" class="pilcrow">¶</a>
</li>
            <li id="section-4.2.3-5.5">"z", encoded as 0x617a.<a href="#section-4.2.3-5.5" class="pilcrow">¶</a>
</li>
            <li id="section-4.2.3-5.6">[-1], encoded as 0x8120.<a href="#section-4.2.3-5.6" class="pilcrow">¶</a>
</li>
            <li id="section-4.2.3-5.7">"aa", encoded as 0x626161.<a href="#section-4.2.3-5.7" class="pilcrow">¶</a>
</li>
            <li id="section-4.2.3-5.8">[100], encoded as 0x811864.<a href="#section-4.2.3-5.8" class="pilcrow">¶</a>
</li>
          </ol>
<aside id="section-4.2.3-6">
            <p id="section-4.2.3-6.1">Although <span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span> used the term "Canonical CBOR" for its form of
requirements on deterministic encoding, this document avoids this term
because "canonicalization" is often associated with specific uses of deterministic
encoding only.  The terms are essentially interchangeable, however, and
the set of core requirements in this document could also be
called "Canonical CBOR", while the length-first-ordered version of that
could be called "Old Canonical CBOR".<a href="#section-4.2.3-6.1" class="pilcrow">¶</a></p>
</aside>
</section>
</div>
</section>
</div>
</section>
</div>
<div id="creating-cbor-based-protocols">
<section id="section-5">
      <h2 id="name-creating-cbor-based-protoco">
<a href="#section-5" class="section-number selfRef">5. </a><a href="#name-creating-cbor-based-protoco" class="section-name selfRef">Creating CBOR-Based Protocols</a>
      </h2>
<p id="section-5-1">Data formats such as CBOR are often used in environments where there
is no format negotiation. A specific design goal of CBOR is to not
need any included or assumed schema: a decoder can take a CBOR item
and decode it with no other knowledge.<a href="#section-5-1" class="pilcrow">¶</a></p>
<p id="section-5-2">Of course, in real-world implementations, the encoder and the decoder
will have a shared view of what should be in a CBOR data item.  For
example, an agreed-to format might be "the item is an array whose
first value is a UTF-8 string, second value is an integer, and
subsequent values are zero or more floating-point numbers" or "the
item is a map that has byte strings for keys and contains a
pair whose key is 0xab01".<a href="#section-5-2" class="pilcrow">¶</a></p>
<p id="section-5-3">CBOR-based protocols <span class="bcp14">MUST</span> specify how their decoders handle
invalid and other unexpected data.  CBOR-based protocols
<span class="bcp14">MAY</span> specify that they treat arbitrary valid data as unexpected.
Encoders for CBOR-based protocols <span class="bcp14">MUST</span> produce only valid items, that
is, the protocol cannot be designed to make use of invalid items.  An
encoder can be capable of encoding as many or as few types of values
as is required by the protocol in which it is used; a decoder can be
capable of understanding as many or as few types of values as is
required by the protocols in which it is used. This lack of
restrictions allows CBOR to be used in extremely constrained
environments.<a href="#section-5-3" class="pilcrow">¶</a></p>
<p id="section-5-4">The rest of this section discusses some considerations in creating CBOR-based
protocols.  With few exceptions, it is advisory only and explicitly excludes any language
from BCP 14 <span>[<a href="#RFC2119" class="xref">RFC2119</a>]</span> <span>[<a href="#RFC8174" class="xref">RFC8174</a>]</span> other than words that could be interpreted as "<span class="bcp14">MAY</span>" in
the sense of BCP 14.  The exceptions aim at facilitating
interoperability of CBOR-based protocols while making use of a wide variety of
both generic and application-specific encoders and decoders.<a href="#section-5-4" class="pilcrow">¶</a></p>
<div id="cbor-in-streaming-applications">
<section id="section-5.1">
        <h3 id="name-cbor-in-streaming-applicati">
<a href="#section-5.1" class="section-number selfRef">5.1. </a><a href="#name-cbor-in-streaming-applicati" class="section-name selfRef">CBOR in Streaming Applications</a>
        </h3>
<p id="section-5.1-1">In a streaming application, a data stream may be composed of a
sequence of CBOR data items concatenated back-to-back. In such an
environment, the decoder immediately begins decoding a new data item
if data is found after the end of a previous data item.<a href="#section-5.1-1" class="pilcrow">¶</a></p>
<p id="section-5.1-2">Not all of the bytes making up a data item may be immediately
available to the decoder; some decoders will buffer additional data
until a complete data item can be presented to the application.  Other
decoders can present partial information about a top-level data item
to an application, such as the nested data items that could already be
decoded, or even parts of a byte string that hasn't completely arrived
yet.
Such an application also <span class="bcp14">MUST</span> have a matching streaming security mechanism, where
the desired protection is available for incremental data presented to the
application.<a href="#section-5.1-2" class="pilcrow">¶</a></p>
<p id="section-5.1-3">Note that some applications and protocols will not want to use
indefinite-length encoding.  Using indefinite-length encoding allows
an encoder to not need to marshal all the data for counting, but it
requires a decoder to allocate increasing amounts of memory while
waiting for the end of the item. This might be fine for some
applications but not others.<a href="#section-5.1-3" class="pilcrow">¶</a></p>
</section>
</div>
<div id="generic">
<section id="section-5.2">
        <h3 id="name-generic-encoders-and-decode">
<a href="#section-5.2" class="section-number selfRef">5.2. </a><a href="#name-generic-encoders-and-decode" class="section-name selfRef">Generic Encoders and Decoders</a>
        </h3>
<p id="section-5.2-1">A generic CBOR decoder can decode all well-formed encoded CBOR data items and
present the data items to an application.  See <a href="#pseudocode" class="xref">Appendix C</a>.
(The diagnostic notation, <a href="#diagnostic-notation" class="xref">Section 8</a>, may be used to
present well-formed CBOR values to humans.)<a href="#section-5.2-1" class="pilcrow">¶</a></p>
<p id="section-5.2-2">Generic CBOR encoders provide an application interface that allows the
application to specify any well-formed value to be encoded as a CBOR
data item, including simple values and tags unknown to the encoder.<a href="#section-5.2-2" class="pilcrow">¶</a></p>
<p id="section-5.2-3">Even though CBOR attempts to minimize these cases, not all well-formed
CBOR data is valid: for example, the encoded text string <code>0x62c0ae</code>
does not contain valid UTF-8 (because <span>[<a href="#RFC3629" class="xref">RFC3629</a>]</span> requires always using the shortest
form) and so is not a valid CBOR item.
Also, specific tags may
make semantic constraints that may be violated, for instance, by a bignum tag
enclosing another tag or by an instance of tag number 0 containing a byte
string or containing a text string with contents that do not match the 
<code>date-time</code> production of <span>[<a href="#RFC3339" class="xref">RFC3339</a>]</span>.  There is
no requirement that generic encoders and decoders make unnatural
choices for their application interface to enable the processing of
invalid data.  Generic encoders and decoders are expected to forward
simple values and tags even if their specific codepoints are not
registered at the time the encoder/decoder is written
(<a href="#validity-checking" class="xref">Section 5.4</a>).<a href="#section-5.2-3" class="pilcrow">¶</a></p>
</section>
</div>
<div id="semantic-errors">
<section id="section-5.3">
        <h3 id="name-validity-of-items">
<a href="#section-5.3" class="section-number selfRef">5.3. </a><a href="#name-validity-of-items" class="section-name selfRef">Validity of Items</a>
        </h3>
<p id="section-5.3-1">A well-formed but invalid CBOR data item (<a href="#terminology" class="xref">Section 1.2</a>) presents a problem with
interpreting the data encoded in it in the CBOR data model.  A
CBOR-based protocol could be specified in several layers, in which the
lower layers don't process the semantics of some of the CBOR data they
forward.  These layers can't notice any validity errors in data they don't
process and <span class="bcp14">MUST</span> forward that data as-is.  The first layer that does
process the semantics of an invalid CBOR item <span class="bcp14">MUST</span> pick one of two
choices:<a href="#section-5.3-1" class="pilcrow">¶</a></p>
<ol start="1" type="1" class="normal type-1" id="section-5.3-2">
<li id="section-5.3-2.1">Replace the problematic item with an error marker and continue with
the next item, or<a href="#section-5.3-2.1" class="pilcrow">¶</a>
</li>
          <li id="section-5.3-2.2">Issue an error and stop processing altogether.<a href="#section-5.3-2.2" class="pilcrow">¶</a>
</li>
        </ol>
<p id="section-5.3-3">A CBOR-based protocol <span class="bcp14">MUST</span> specify which of these options its decoders
take for each kind of invalid item they might encounter.<a href="#section-5.3-3" class="pilcrow">¶</a></p>
<p id="section-5.3-4">Such problems might occur at the basic validity level of CBOR or in
the context of tags (tag validity).<a href="#section-5.3-4" class="pilcrow">¶</a></p>
<div id="basic-validity">
<section id="section-5.3.1">
          <h4 id="name-basic-validity">
<a href="#section-5.3.1" class="section-number selfRef">5.3.1. </a><a href="#name-basic-validity" class="section-name selfRef">Basic validity</a>
          </h4>
<p id="section-5.3.1-1">Two kinds of validity errors can occur in the basic generic data model:<a href="#section-5.3.1-1" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-5.3.1-2">
            <dt id="section-5.3.1-2.1">Duplicate keys in a map:</dt>
            <dd style="margin-left: 1.5em" id="section-5.3.1-2.2">
  Generic decoders (<a href="#generic" class="xref">Section 5.2</a>) make data available to applications
using the native CBOR data model.  That data model includes maps
(key-value mappings with unique keys), not multimaps (key-value
mappings where multiple entries can have the same key).  Thus, a
generic decoder that gets a CBOR map item that has duplicate keys
will decode to a map with only one instance of that key, or it might
stop processing altogether.  On the other hand, a "streaming
decoder" may not even be able to notice.  See <a href="#map-keys" class="xref">Section 5.6</a> for more
discussion of keys in maps.<a href="#section-5.3.1-2.2" class="pilcrow">¶</a>
</dd>
            <dd class="break"></dd>
<dt id="section-5.3.1-2.3">Invalid UTF-8 string:</dt>
            <dd style="margin-left: 1.5em" id="section-5.3.1-2.4">
  A decoder might or might not want to verify that the sequence of
bytes in a UTF-8 string (major type 3) is actually valid UTF-8 and
react appropriately.<a href="#section-5.3.1-2.4" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
</dl>
</section>
</div>
<div id="tag-validity">
<section id="section-5.3.2">
          <h4 id="name-tag-validity">
<a href="#section-5.3.2" class="section-number selfRef">5.3.2. </a><a href="#name-tag-validity" class="section-name selfRef">Tag validity</a>
          </h4>
<p id="section-5.3.2-1">Two additional kinds of validity errors are introduced by adding tags
to the basic generic data model:<a href="#section-5.3.2-1" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-5.3.2-2">
            <dt id="section-5.3.2-2.1">Inadmissible type for tag content:</dt>
            <dd style="margin-left: 1.5em" id="section-5.3.2-2.2">
  Tag numbers (<a href="#tags" class="xref">Section 3.4</a>) specify what type of data item is supposed to be
used as their tag content; for example, the tag numbers for unsigned or negative bignums are
supposed to be put on byte strings. A decoder that decodes the
tagged data item into a native representation (a native big integer
in this example) is expected to check the type of the data item
being tagged.  Even decoders that don't have such native
representations available in their environment may perform the check
on those tags known to them and react appropriately.<a href="#section-5.3.2-2.2" class="pilcrow">¶</a>
</dd>
            <dd class="break"></dd>
<dt id="section-5.3.2-2.3">Inadmissible value for tag content:</dt>
            <dd style="margin-left: 1.5em" id="section-5.3.2-2.4">
  The type of data item may be admissible for a tag's content, but the
specific value may not be; e.g., a value of "yesterday" is not
acceptable for the content of tag 0, even though it properly is a
text string.  A decoder that normally ingests such tags into
equivalent platform types might present this tag to the application
in a similar way to how it would present a tag with an unknown tag
number (<a href="#validity-checking" class="xref">Section 5.4</a>).<a href="#section-5.3.2-2.4" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
</dl>
</section>
</div>
</section>
</div>
<div id="validity-checking">
<section id="section-5.4">
        <h3 id="name-validity-and-evolution">
<a href="#section-5.4" class="section-number selfRef">5.4. </a><a href="#name-validity-and-evolution" class="section-name selfRef">Validity and Evolution</a>
        </h3>
<p id="section-5.4-1">A decoder with validity checking will expend the effort to reliably
detect data items with validity errors. For example, such a
decoder needs to have an API that reports an error (and does not
return data) for a CBOR data item that contains any of the validity
errors listed in the previous subsection.<a href="#section-5.4-1" class="pilcrow">¶</a></p>
<p id="section-5.4-2">The set of tags defined in the "Concise Binary Object
        Representation (CBOR) Tags" registry (<a href="#ianatags" class="xref">Section 9.2</a>), as well as the set of simple values defined in
        the "Concise Binary Object Representation (CBOR) Simple Values"
        registry (<a href="#ianasimple" class="xref">Section 9.1</a>), can grow at
        any time beyond the set understood by a generic decoder.  A
        validity-checking decoder can do one of two things when it encounters
        such a case that it does not recognize:<a href="#section-5.4-2" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-5.4-3.1">It can report an error (and not return data).
Note that treating this case as an error can cause ossification and is
thus not encouraged. This error
is not a validity error, per se.  This kind of error is more likely
to be raised by a decoder that would be performing validity checking
if this were a known case.<a href="#section-5.4-3.1" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-5.4-3.2">It can emit the unknown item (type, value, and, for tags, the
decoded tagged data item) to the application calling the decoder,
and then give the application
an indication that the decoder did not recognize that tag
number or simple value.<a href="#section-5.4-3.2" class="pilcrow">¶</a>
</li>
        </ul>
<p id="section-5.4-4">The latter approach, which is also appropriate for decoders that do
not support validity checking, provides forward compatibility with
newly registered tags and simple values without the requirement to
update the encoder at the same time as the calling application.  (For
this, the decoder's API needs the ability to mark unknown
items so that the calling application can handle them in a manner
appropriate for the program.)<a href="#section-5.4-4" class="pilcrow">¶</a></p>
<p id="section-5.4-5">Since some of the processing needed for validity checking may have an
appreciable cost (in particular with duplicate detection for maps),
support of validity checking is not a requirement placed on all CBOR
decoders.<a href="#section-5.4-5" class="pilcrow">¶</a></p>
<p id="section-5.4-6">Some encoders will rely on their applications to provide input data in
such a way that valid CBOR results from the encoder.  A generic
encoder may also want to provide a validity-checking mode where it
reliably limits its output to valid CBOR, independent of whether or
not its application is indeed providing API-conformant data.<a href="#section-5.4-6" class="pilcrow">¶</a></p>
</section>
</div>
<div id="numbers">
<section id="section-5.5">
        <h3 id="name-numbers">
<a href="#section-5.5" class="section-number selfRef">5.5. </a><a href="#name-numbers" class="section-name selfRef">Numbers</a>
        </h3>
<p id="section-5.5-1">CBOR-based protocols should take into account that different language
environments pose different restrictions on the range and precision of
numbers that are representable.  For example, the basic JavaScript number
system treats all numbers as floating-point values, which may result in
the silent loss of precision in decoding integers with more than 53
significant bits.
Another example is that, since CBOR keeps the sign bit for its integer
representation in the major type, it has one bit more for signed
numbers of a certain length (e.g., -2<sup>64</sup>..2<sup>64</sup>-1 for 1+8-byte
integers) than the typical platform signed integer representation of
the same length (-2<sup>63</sup>..2<sup>63</sup>-1 for 8-byte int64_t).
A protocol that uses numbers should define its
expectations on the handling of nontrivial numbers in decoders and
receiving applications.<a href="#section-5.5-1" class="pilcrow">¶</a></p>
<p id="section-5.5-2">A CBOR-based protocol that includes floating-point numbers can
restrict which of the three formats (half-precision, single-precision,
and double-precision) are to be supported.  For an integer-only
application, a protocol may want to completely exclude the use of
floating-point values.<a href="#section-5.5-2" class="pilcrow">¶</a></p>
<p id="section-5.5-3">A CBOR-based protocol designed for compactness may want to exclude
specific integer encodings that are longer than necessary for the
application, such as to save the need to implement 64-bit integers.
There is an expectation that encoders will use the most compact
integer representation that can represent a given value.  However, a
compact application that does not require deterministic encoding
should accept values that use a longer-than-needed
encoding (such as encoding "0" as 0b000_11001 followed by two bytes of
0x00) as long as the application can decode an integer of the given
size.
Similar considerations apply to floating-point values; decoding both
preferred serializations and longer-than-needed ones is recommended.<a href="#section-5.5-3" class="pilcrow">¶</a></p>
<p id="section-5.5-4">CBOR-based protocols for constrained applications that provide a
choice between representing a specific number as an integer and
as a decimal fraction or bigfloat (such as when the exponent is small
and nonnegative) might express a quality-of-implementation expectation
that the integer representation is used directly.<a href="#section-5.5-4" class="pilcrow">¶</a></p>
</section>
</div>
<div id="map-keys">
<section id="section-5.6">
        <h3 id="name-specifying-keys-for-maps">
<a href="#section-5.6" class="section-number selfRef">5.6. </a><a href="#name-specifying-keys-for-maps" class="section-name selfRef">Specifying Keys for Maps</a>
        </h3>
<p id="section-5.6-1">The encoding and decoding applications need to agree on what types of
keys are going to be used in maps.  In applications that need to
interwork with JSON-based applications, conversion is simplified by
limiting keys to text strings only; otherwise, there has to be a specified
mapping from the other CBOR types to text strings, and this
often leads to implementation errors.  In applications where keys are
numeric in nature, and numeric ordering of keys is important to the
application, directly using the numbers for the keys is useful.<a href="#section-5.6-1" class="pilcrow">¶</a></p>
<p id="section-5.6-2">If multiple types of keys are to be used, consideration should be
given to how these types would be represented in the specific
programming environments that are to be used.  For example, in
JavaScript Maps <span>[<a href="#ECMA262" class="xref">ECMA262</a>]</span>, a key of integer 1 cannot be
distinguished from a key of floating-point 1.0. This means that, if integer
keys are used, the protocol needs to avoid the use of
floating-point keys the values of which happen to be integer numbers in the same map.<a href="#section-5.6-2" class="pilcrow">¶</a></p>
<p id="section-5.6-3">Decoders that deliver data items nested within a CBOR data item
immediately on decoding them ("streaming decoders") often do not keep
the state that is necessary to ascertain uniqueness of a key in a map.
Similarly, an encoder that can start encoding data items before the
enclosing data item is completely available ("streaming encoder") may
want to reduce its overhead significantly by relying on its data
source to maintain uniqueness.<a href="#section-5.6-3" class="pilcrow">¶</a></p>
<p id="section-5.6-4">A CBOR-based protocol <span class="bcp14">MUST</span> define what
to do when a receiving application sees multiple identical keys in
a map.  The resulting rule in the protocol <span class="bcp14">MUST</span> respect the CBOR
data model: it cannot prescribe a specific handling of the entries
with the identical keys, except that it might have a rule that having
identical keys in a map indicates a malformed map and that the decoder
has to stop with an error.
When processing maps that exhibit entries with duplicate keys, a generic
decoder might do one of the following:<a href="#section-5.6-4" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-5.6-5.1">Not accept maps with duplicate keys (that is, enforce validity for maps,
see also <a href="#validity-checking" class="xref">Section 5.4</a>).  These generic decoders are
universally useful.  An application may still need to perform its
own duplicate checking based on application rules (for instance, if
the application equates integers and floating-point values in map
key positions for specific maps).<a href="#section-5.6-5.1" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-5.6-5.2">Pass all map entries to the application, including ones with
duplicate keys.  This requires that the application handle (check
against) duplicate keys, even if the application rules are identical
to the generic data model rules.<a href="#section-5.6-5.2" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-5.6-5.3">Lose some entries with duplicate keys, e.g., deliver only the
final (or first) entry out of the entries with the same key.  With
such a generic decoder, applications may get different results for a
specific key on different runs, and with different generic decoders,
which value is returned is based on generic decoder
implementation and the actual order of keys in the map.  In
particular, applications cannot validate key uniqueness on their own
as they do not necessarily see all entries; they may not be able to
use such a generic decoder if they need to validate key
uniqueness.  These generic decoders can only be used in situations
where the data source and transfer always
provide valid maps; this is not possible if the data source and transfer can be attacked.<a href="#section-5.6-5.3" class="pilcrow">¶</a>
</li>
        </ul>
<p id="section-5.6-6">Generic decoders need to document which of these three approaches they
implement.<a href="#section-5.6-6" class="pilcrow">¶</a></p>
<p id="section-5.6-7">The CBOR data model for maps does not allow ascribing semantics to the
order of the key/value pairs in the map representation.  Thus, a
CBOR-based protocol <span class="bcp14">MUST NOT</span> specify that changing the key/value pair
order in a map changes the semantics, except to specify that some
orders are disallowed, for example, where they would not meet the
requirements of a deterministic
encoding (<a href="#det-enc" class="xref">Section 4.2</a>).
(Any secondary effects of map ordering such as on timing, cache usage,
and other potential side channels are not considered part of the
semantics but may be enough reason on their own for a protocol to require a
deterministic encoding format.)<a href="#section-5.6-7" class="pilcrow">¶</a></p>
<p id="section-5.6-8">Applications for constrained devices should consider using small 
   integers as keys if they have maps with a small number of frequently 
   used keys; for instance, a set of 24 or fewer
   keys can be encoded in a single byte as unsigned integers, up to 
   48 if negative integers are also used.  Less frequently
   occurring keys can then use integers with longer encodings.<a href="#section-5.6-8" class="pilcrow">¶</a></p>
<div id="equivalence-of-keys">
<section id="section-5.6.1">
          <h4 id="name-equivalence-of-keys">
<a href="#section-5.6.1" class="section-number selfRef">5.6.1. </a><a href="#name-equivalence-of-keys" class="section-name selfRef">Equivalence of Keys</a>
          </h4>
<p id="section-5.6.1-1">The specific data model that applies to a CBOR data item is used to
determine whether keys occurring in maps are duplicates or distinct.<a href="#section-5.6.1-1" class="pilcrow">¶</a></p>
<p id="section-5.6.1-2">At the generic data model level, numerically equivalent integer and
floating-point values are distinct from each other, as they are from
the various big numbers (Tags 2 to 5).  Similarly, text strings are
distinct from byte strings, even if composed of the same bytes.  A
tagged value is distinct from an untagged value or from a value tagged
with a different tag number.<a href="#section-5.6.1-2" class="pilcrow">¶</a></p>
<p id="section-5.6.1-3">Within each of these groups, numeric values are distinct unless they
are numerically equal (specifically, -0.0 is equal to 0.0); for the
purpose of map key equivalence, NaN 
values are equivalent if they have the same significand after
zero-extending both significands at the right to 64 bits.<a href="#section-5.6.1-3" class="pilcrow">¶</a></p>
<p id="section-5.6.1-4">Both byte strings and text strings are compared 
byte by byte, arrays are compared element by element, and are equal if they have 
the same number of bytes/elements and the same values at the same 
positions.  Two maps are equal if they have the same set of pairs regardless of
their order; pairs are equal if both the key and value are equal.<a href="#section-5.6.1-4" class="pilcrow">¶</a></p>
<p id="section-5.6.1-5">Tagged values are equal if both the tag number and the tag content are equal.
(Note that a generic decoder that provides processing for a specific
tag may not be able to distinguish some semantically equivalent
values, e.g., if leading zeroes occur in the content of tag 2 or tag 3
(<a href="#bignums" class="xref">Section 3.4.3</a>).)
Simple values are equal if they simply have the same value.
Nothing else is equal in the generic data model; a simple value 2 is
not equivalent to an integer 2, and an array is never equivalent to a map.<a href="#section-5.6.1-5" class="pilcrow">¶</a></p>
<p id="section-5.6.1-6">As discussed in <a href="#specific-data-models" class="xref">Section 2.2</a>, specific data models can
make values equivalent for the purpose of comparing map keys that are
distinct in the generic data model.  Note that this implies that a
generic decoder may deliver a decoded map to an application that needs
to be checked for duplicate map keys by that application
(alternatively, the decoder may provide a programming interface to
perform this service for the application).  Specific data models
are not able to distinguish values for map keys that are equal for this purpose
at the generic data model level.<a href="#section-5.6.1-6" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
<div id="undefined-values">
<section id="section-5.7">
        <h3 id="name-undefined-values">
<a href="#section-5.7" class="section-number selfRef">5.7. </a><a href="#name-undefined-values" class="section-name selfRef">Undefined Values</a>
        </h3>
<p id="section-5.7-1">In some CBOR-based protocols, the simple value (<a href="#fpnocont" class="xref">Section 3.3</a>) of
<code>undefined</code> might be used by an encoder as a substitute for a data item
with an encoding problem, in order to allow the rest of the enclosing
data items to be encoded without harm.<a href="#section-5.7-1" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
<div id="converting-data-between-cbor-and-json">
<section id="section-6">
      <h2 id="name-converting-data-between-cbo">
<a href="#section-6" class="section-number selfRef">6. </a><a href="#name-converting-data-between-cbo" class="section-name selfRef">Converting Data between CBOR and JSON</a>
      </h2>
<p id="section-6-1">This section gives non-normative advice about converting between CBOR
and JSON. Implementations of converters <span class="bcp14">MAY</span> use whichever
advice here they want.<a href="#section-6-1" class="pilcrow">¶</a></p>
<p id="section-6-2">It is worth noting that a JSON text is a sequence of characters, not
an encoded sequence of bytes, while a CBOR data item consists of
bytes, not characters.<a href="#section-6-2" class="pilcrow">¶</a></p>
<div id="converting-from-cbor-to-json">
<section id="section-6.1">
        <h3 id="name-converting-from-cbor-to-jso">
<a href="#section-6.1" class="section-number selfRef">6.1. </a><a href="#name-converting-from-cbor-to-jso" class="section-name selfRef">Converting from CBOR to JSON</a>
        </h3>
<p id="section-6.1-1">Most of the types in CBOR have direct analogs in JSON. However, some
do not, and someone implementing a CBOR-to-JSON converter has to
consider what to do in those cases. The following non-normative advice
deals with these by converting them to a single substitute value, such
as a JSON null.<a href="#section-6.1-1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-6.1-2.1">An integer (major type 0 or 1) becomes a JSON number.<a href="#section-6.1-2.1" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.2">A byte string (major type 2) that is not embedded in a tag that
specifies a proposed encoding is encoded in base64url without
padding and becomes a JSON string.<a href="#section-6.1-2.2" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.3">A UTF-8 string (major type 3) becomes a JSON string.  Note that JSON
requires escaping certain characters (<span>[<a href="#RFC8259" class="xref">RFC8259</a>], <a href="https://www.rfc-editor.org/rfc/rfc8259#section-7" class="relref">Section 7</a></span>):
quotation mark (U+0022), reverse solidus (U+005C), and the "C0
control characters" (U+0000 through U+001F).  All other characters
are copied unchanged into the JSON UTF-8 string.<a href="#section-6.1-2.3" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.4">An array (major type 4) becomes a JSON array.<a href="#section-6.1-2.4" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.5">A map (major type 5) becomes a JSON object.  This is possible
directly only if all keys are UTF-8 strings.  A converter might also
convert other keys into UTF-8 strings (such as by converting
integers into strings containing their decimal representation);
however, doing so introduces a danger of key collision.
Note also that, if tags on UTF-8 strings are ignored as proposed
below, this will cause a key
collision if the tags are different but the strings are the same.<a href="#section-6.1-2.5" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.6">False (major type 7, additional information 20) becomes a JSON
false.<a href="#section-6.1-2.6" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.7">True (major type 7, additional information 21) becomes a JSON true.<a href="#section-6.1-2.7" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.8">Null (major type 7, additional information 22) becomes a JSON null.<a href="#section-6.1-2.8" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.9">A floating-point value (major type 7, additional information 25
through 27) becomes a JSON number if it is finite (that is, it can
be represented in a JSON number); if the value is non-finite (NaN,
or positive or negative Infinity), it is represented by the
substitute value.<a href="#section-6.1-2.9" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.10">Any other simple value (major type 7, any additional information
value not yet discussed) is represented by the substitute value.<a href="#section-6.1-2.10" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.11">A bignum (major type 6, tag number 2 or 3) is represented by encoding
its byte string in base64url without padding and becomes a JSON
string.  For tag number 3 (negative bignum), a "~" (ASCII tilde) is
inserted before the base-encoded value. (The conversion to a binary
blob instead of a number is to prevent a likely numeric overflow for
the JSON decoder.)<a href="#section-6.1-2.11" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.12">A byte string with an encoding hint (major type 6, tag number 21
through 23) is encoded as described by the hint and becomes a JSON string.<a href="#section-6.1-2.12" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.13">For all other tags (major type 6, any other tag number), the tag
content is represented as a JSON value; the tag number is ignored.<a href="#section-6.1-2.13" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.1-2.14">Indefinite-length items are made definite before conversion.<a href="#section-6.1-2.14" class="pilcrow">¶</a>
</li>
        </ul>
<p id="section-6.1-3">A CBOR-to-JSON converter may want to keep to the JSON profile I-JSON
<span>[<a href="#RFC7493" class="xref">RFC7493</a>]</span>, to maximize interoperability and increase confidence
that the JSON output can be processed with predictable results.  For
example, this has implications on the range of integers that can be
represented reliably, as well as on the top-level items that may be
supported by older JSON implementations.<a href="#section-6.1-3" class="pilcrow">¶</a></p>
</section>
</div>
<div id="converting-from-json">
<section id="section-6.2">
        <h3 id="name-converting-from-json-to-cbo">
<a href="#section-6.2" class="section-number selfRef">6.2. </a><a href="#name-converting-from-json-to-cbo" class="section-name selfRef">Converting from JSON to CBOR</a>
        </h3>
<p id="section-6.2-1">All JSON values, once decoded, directly map into one or more CBOR
values.  As with any kind of CBOR generation, decisions have to be
made with respect to number representation.  In a suggested
conversion:<a href="#section-6.2-1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-6.2-2.1">JSON numbers without fractional parts (integer numbers) are
represented as integers (major types 0 and 1, possibly major type 6,
tag number 2 and 3), choosing the shortest form; integers longer than
an implementation-defined threshold may instead be represented as
floating-point values.  The
default range that is represented as integer is
-2<sup>53</sup>+1..2<sup>53</sup>-1 (fully exploiting the range for exact integers
in the binary64 representation often used for decoding JSON <span>[<a href="#RFC7493" class="xref">RFC7493</a>]</span>).
A CBOR-based protocol, or a generic converter implementation,
may choose -2<sup>32</sup>..2<sup>32</sup>-1 or -2<sup>64</sup>..2<sup>64</sup>-1 (fully
using the integer ranges available in CBOR with uint32_t or
uint64_t, respectively) or even -2<sup>31</sup>..2<sup>31</sup>-1 or
-2<sup>63</sup>..2<sup>63</sup>-1 (using popular ranges for two's complement
signed integers).
(If
the JSON was generated from a JavaScript implementation, its
precision is already limited to 53 bits maximum.)<a href="#section-6.2-2.1" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-6.2-2.2">Numbers with fractional parts are represented as floating-point
values, performing the decimal-to-binary conversion based on the
precision provided by IEEE 754 binary64.
The mathematical value of the JSON number is converted to binary64
using the roundTiesToEven procedure in Section 4.3.1 of <span>[<a href="#IEEE754" class="xref">IEEE754</a>]</span>.
Then, when encoding in
CBOR, the preferred serialization uses the shortest floating-point
representation exactly representing this conversion result; for
instance, 1.5 is represented in a 16-bit floating-point value (not
all implementations will be capable of efficiently finding the
minimum form, though).  Instead of using the default binary64
precision, there may be an implementation-defined limit to the
precision of the conversion that will affect the precision of the
represented values. Decimal representation should only be used on
the CBOR side if that is specified in a protocol.<a href="#section-6.2-2.2" class="pilcrow">¶</a>
</li>
        </ul>
<p id="section-6.2-3">CBOR has been designed to generally provide a more compact encoding
than JSON.  One implementation strategy that might come to mind is to
perform a JSON-to-CBOR encoding in place in a single buffer.  This
strategy would need to carefully consider a number of pathological
cases, such as that some strings represented with no or very few
escapes and longer (or much longer) than 255 bytes may expand when
encoded as UTF-8 strings in CBOR.  Similarly, a few of the binary
floating-point representations might cause expansion from some short
decimal representations (1.1, 1e9) in JSON.  This may be hard to get
right, and any ensuing vulnerabilities may be exploited by an
attacker.<a href="#section-6.2-3" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
<div id="future-evolution-of-cbor">
<section id="section-7">
      <h2 id="name-future-evolution-of-cbor">
<a href="#section-7" class="section-number selfRef">7. </a><a href="#name-future-evolution-of-cbor" class="section-name selfRef">Future Evolution of CBOR</a>
      </h2>
<p id="section-7-1">Successful protocols evolve over time.  New ideas appear,
implementation platforms improve, related protocols are developed and
evolve, and new requirements from applications and protocols are
added.  Facilitating protocol evolution is therefore an important
design consideration for any protocol development.<a href="#section-7-1" class="pilcrow">¶</a></p>
<p id="section-7-2">For protocols that will use CBOR, CBOR provides some useful mechanisms
to facilitate their evolution.  Best practices for this are well
known, particularly from JSON format development of JSON-based
protocols.  Therefore, such best practices are outside the scope of
this specification.<a href="#section-7-2" class="pilcrow">¶</a></p>
<p id="section-7-3">However, facilitating the evolution of CBOR itself is very well within
its scope.  CBOR is designed to both provide a stable basis for
development of CBOR-based protocols and to be able to evolve.  Since a
successful protocol may live for decades, CBOR needs to be designed
for decades of use and evolution.  This section provides some guidance
for the evolution of CBOR.  It is necessarily more subjective than
other parts of this document.  It is also necessarily incomplete, lest
it turn into a textbook on protocol development.<a href="#section-7-3" class="pilcrow">¶</a></p>
<div id="extension-points">
<section id="section-7.1">
        <h3 id="name-extension-points">
<a href="#section-7.1" class="section-number selfRef">7.1. </a><a href="#name-extension-points" class="section-name selfRef">Extension Points</a>
        </h3>
<p id="section-7.1-1">In a protocol design, opportunities for evolution are often included
in the form of extension points.  For example, there may be a
codepoint space that is not fully allocated from the outset, and the
protocol is designed to tolerate and embrace implementations that
start using more codepoints than initially allocated.<a href="#section-7.1-1" class="pilcrow">¶</a></p>
<p id="section-7.1-2">Sizing the codepoint space may be difficult because the range required
may be hard to predict.  Protocol designs should attempt to make the
codepoint space large enough so that it can slowly be filled over the
intended lifetime of the protocol.<a href="#section-7.1-2" class="pilcrow">¶</a></p>
<p id="section-7.1-3">CBOR has three major extension points:<a href="#section-7.1-3" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-7.1-4">
          <dt id="section-7.1-4.1">the "simple" space (values in major type 7):</dt>
          <dd style="margin-left: 1.5em" id="section-7.1-4.2">Of the 24 efficient
(and 224 slightly less efficient) values, only a small number have
been allocated.  Implementations receiving an unknown simple data
item may easily be able to process it as such, given that the structure of
the value is indeed simple. The IANA registry in
<a href="#ianasimple" class="xref">Section 9.1</a> is the appropriate way to address the
extensibility of this codepoint space.<a href="#section-7.1-4.2" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-7.1-4.3">the "tag" space (values in major type 6):</dt>
          <dd style="margin-left: 1.5em" id="section-7.1-4.4"> The total codepoint space
is abundant; only a tiny part of it has
been allocated.  However, not all of these codepoints are equally
efficient: the first 24 only consume a single ("1+0") byte, and
half of them have already been allocated. The next 232 values only
consume two ("1+1") bytes, with nearly a quarter already allocated.
These subspaces need some curation to last for a few more decades.
Implementations receiving an unknown tag number can choose to
process just the enclosed tag content or, preferably, to
process the tag as an unknown tag number wrapping the
tag content. The IANA registry in <a href="#ianatags" class="xref">Section 9.2</a> is the appropriate way to
address the extensibility of this codepoint space.<a href="#section-7.1-4.4" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-7.1-4.5">the "additional information" space:</dt>
          <dd style="margin-left: 1.5em" id="section-7.1-4.6">An implementation receiving an
unknown additional information value has no way to continue decoding,
so allocating codepoints in this space is a major step beyond just
exercising an extension point.  There are
also very few codepoints left.  See also <a href="#curating" class="xref">Section 7.2</a>.<a href="#section-7.1-4.6" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
</dl>
</section>
</div>
<div id="curating">
<section id="section-7.2">
        <h3 id="name-curating-the-additional-inf">
<a href="#section-7.2" class="section-number selfRef">7.2. </a><a href="#name-curating-the-additional-inf" class="section-name selfRef">Curating the Additional Information Space</a>
        </h3>
<p id="section-7.2-1">The human mind is sometimes drawn to filling in little perceived gaps
to make something neat.  We expect the remaining gaps in the codepoint
space for the additional information values to be an attractor for new
ideas, just because they are there.<a href="#section-7.2-1" class="pilcrow">¶</a></p>
<p id="section-7.2-2">The present specification does not manage the additional information
codepoint space by an IANA registry.  Instead, allocations out of this
space can only be done by updating this specification.<a href="#section-7.2-2" class="pilcrow">¶</a></p>
<p id="section-7.2-3">For an additional information value of n &gt;= 24, the size of the
additional data typically is 2<sup>n-24</sup> bytes.  Therefore, additional
information values 28 and 29 should be viewed as candidates for
128-bit and 256-bit quantities, in case a need arises to add them to
the protocol.  Additional information value 30 is then the only
additional information value available for general allocation, and
there should be a very good reason for allocating it before assigning
it through an update of the present specification.<a href="#section-7.2-3" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
<div id="diagnostic-notation">
<section id="section-8">
      <h2 id="name-diagnostic-notation">
<a href="#section-8" class="section-number selfRef">8. </a><a href="#name-diagnostic-notation" class="section-name selfRef">Diagnostic Notation</a>
      </h2>
<p id="section-8-1">CBOR is a binary interchange format.  To facilitate documentation and
debugging, and in particular to facilitate communication between
entities cooperating in debugging, this section defines a simple
human-readable diagnostic notation.  All actual interchange always
happens in the binary format.<a href="#section-8-1" class="pilcrow">¶</a></p>
<p id="section-8-2">Note that this truly is a diagnostic format; it is not meant to be
parsed.  Therefore, no formal definition (as in ABNF) is given in this
document.  (Implementers looking for a text-based format for
representing CBOR data items in configuration files may also want to
consider YAML <span>[<a href="#YAML" class="xref">YAML</a>]</span>.)<a href="#section-8-2" class="pilcrow">¶</a></p>
<p id="section-8-3">The diagnostic notation is loosely based on JSON as it is defined in
RFC 8259, extending it where needed.<a href="#section-8-3" class="pilcrow">¶</a></p>
<p id="section-8-4">The notation borrows the JSON syntax for numbers (integer and
floating-point), True (&gt;true&lt;), False (&gt;false&lt;), Null (&gt;null&lt;), UTF-8
strings, arrays, and maps (maps are called objects in JSON; the
diagnostic notation extends JSON here by allowing any data item in the
key position).  Undefined is written &gt;undefined&lt; as in JavaScript.
The non-finite floating-point numbers Infinity, -Infinity, and NaN are
written exactly as in this sentence (this is also a way they can be
written in JavaScript, although JSON does not allow them).  A tag is
written as an integer number for the tag number, followed by the tag content
in parentheses; for instance, a date in the format specified by RFC 3339 (ISO 8601) could be
notated as:<a href="#section-8-4" class="pilcrow">¶</a></p>
<p style="margin-left: 2.5em" id="section-8-5">0("2013-03-21T20:04:00Z")<a href="#section-8-5" class="pilcrow">¶</a></p>
<p id="section-8-6">or the equivalent relative time as the following:<a href="#section-8-6" class="pilcrow">¶</a></p>
<p style="margin-left: 2.5em" id="section-8-7">1(1363896240)<a href="#section-8-7" class="pilcrow">¶</a></p>
<p id="section-8-8">Byte strings are notated in one of the base encodings, without
padding, enclosed in single quotes, prefixed by &gt;h&lt; for base16,
&gt;b32&lt; for base32, &gt;h32&lt; for base32hex, &gt;b64&lt; for base64 or
base64url (the actual encodings do not overlap, so the string remains
unambiguous).  For example, the byte string 0x12345678 could be
written h'12345678', b32'CI2FM6A', or b64'EjRWeA'.<a href="#section-8-8" class="pilcrow">¶</a></p>
<p id="section-8-9">Unassigned simple values are given as "simple()" with the appropriate
integer in the parentheses. For example, "simple(42)" indicates major
type 7, value 42.<a href="#section-8-9" class="pilcrow">¶</a></p>
<p id="section-8-10">A number of useful extensions to the diagnostic notation defined here are
provided in <span><a href="https://www.rfc-editor.org/rfc/rfc8610#appendix-G" class="relref">Appendix G</a> of [<a href="#RFC8610" class="xref">RFC8610</a>]</span>, "Extended Diagnostic Notation" (EDN).
   Similarly, this notation could be extended in a separate document to 
   provide documentation for NaN payloads, which are not covered in this document.<a href="#section-8-10" class="pilcrow">¶</a></p>
<div id="encoding-indicators">
<section id="section-8.1">
        <h3 id="name-encoding-indicators">
<a href="#section-8.1" class="section-number selfRef">8.1. </a><a href="#name-encoding-indicators" class="section-name selfRef">Encoding Indicators</a>
        </h3>
<p id="section-8.1-1">Sometimes it is useful to indicate in the diagnostic notation which of
several alternative representations were actually used; for example, a
data item written &gt;1.5&lt; by a diagnostic decoder might have been
encoded as a half-, single-, or double-precision float.<a href="#section-8.1-1" class="pilcrow">¶</a></p>
<p id="section-8.1-2">The convention for encoding indicators is that anything starting with
an underscore and all following characters that are alphanumeric or
underscore is an encoding indicator, and can be ignored by anyone not
interested in this information.  For example, <code>_</code> or <code>_3</code>.
Encoding indicators are always
optional.<a href="#section-8.1-2" class="pilcrow">¶</a></p>
<p id="section-8.1-3">A single underscore can be written after the opening brace of a map or
the opening bracket of an array to indicate that the data item was
represented in indefinite-length format.  For example, [_ 1, 2]
contains an indicator that an indefinite-length representation was
used to represent the data item [1, 2].<a href="#section-8.1-3" class="pilcrow">¶</a></p>
<p id="section-8.1-4">An underscore followed by a decimal digit n indicates that the
preceding item (or, for arrays and maps, the item starting with the
preceding bracket or brace) was encoded with an additional information
value of 24+n.  For example, 1.5_1 is a half-precision floating-point
number, while 1.5_3 is encoded as double precision.  This encoding
indicator is not shown in <a href="#examples" class="xref">Appendix A</a>.  (Note that the encoding
indicator "_" is thus an abbreviation of the full form "_7", which is
not used.)<a href="#section-8.1-4" class="pilcrow">¶</a></p>
<p id="section-8.1-5">The detailed chunk structure of byte and text strings of indefinite
length can be
notated in the form (_ h'0123', h'4567') and (_ "foo", "bar").
However, for an indefinite-length string with no chunks inside, (_ )
would be ambiguous as to whether a byte string (0x5fff) or a text string
(0x7fff) is meant and is therefore not used.
The basic forms ''_ and ""_ can be used instead and are reserved for
the case of no chunks only -- not as short forms for the (permitted,
but not really useful) encodings with only empty chunks, which 
need to be notated as (_ ''), (_ ""), etc.,
to preserve the chunk structure.<a href="#section-8.1-5" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
<div id="ianacons">
<section id="section-9">
      <h2 id="name-iana-considerations">
<a href="#section-9" class="section-number selfRef">9. </a><a href="#name-iana-considerations" class="section-name selfRef">IANA Considerations</a>
      </h2>
<p id="section-9-1">IANA has created two registries for new CBOR values. The registries
      are separate, that is, not under an umbrella registry, and follow the
      rules in <span>[<a href="#RFC8126" class="xref">RFC8126</a>]</span>. IANA has also
      assigned a new media type, an associated 
      CoAP Content-Format entry, and a structured syntax suffix.<a href="#section-9-1" class="pilcrow">¶</a></p>
<div id="ianasimple">
<section id="section-9.1">
        <h3 id="name-cbor-simple-values-registry">
<a href="#section-9.1" class="section-number selfRef">9.1. </a><a href="#name-cbor-simple-values-registry" class="section-name selfRef">CBOR Simple Values Registry</a>
        </h3>
<p id="section-9.1-1">IANA has created the "Concise Binary Object Representation (CBOR)
        Simple Values" registry at <span>[<a href="#IANA.cbor-simple-values" class="xref">IANA.cbor-simple-values</a>]</span>. The initial values are shown in <a href="#fpnoconttbl2" class="xref">Table 4</a>.<a href="#section-9.1-1" class="pilcrow">¶</a></p>
<p id="section-9.1-2">New entries in the range 0 to 19 are assigned by Standards Action


 <span>[<a href="#RFC8126" class="xref">RFC8126</a>]</span>.  It
is suggested that IANA allocate values starting
with the number 16 in order to reserve the lower numbers for
contiguous blocks (if any).<a href="#section-9.1-2" class="pilcrow">¶</a></p>
<p id="section-9.1-3">New entries in the range 32 to 255 are assigned by Specification
Required.<a href="#section-9.1-3" class="pilcrow">¶</a></p>
</section>
</div>
<div id="ianatags">
<section id="section-9.2">
        <h3 id="name-cbor-tags-registry">
<a href="#section-9.2" class="section-number selfRef">9.2. </a><a href="#name-cbor-tags-registry" class="section-name selfRef">CBOR Tags Registry</a>
        </h3>
<p id="section-9.2-1">IANA has created the "Concise Binary Object Representation (CBOR)
Tags" registry at <span>[<a href="#IANA.cbor-tags" class="xref">IANA.cbor-tags</a>]</span>.
The tags that were defined in <span>[<a href="#RFC7049" class="xref">RFC7049</a>]</span> 
are described in detail in <a href="#tags" class="xref">Section 3.4</a>,
and other tags have already been defined since then.<a href="#section-9.2-1" class="pilcrow">¶</a></p>
<p id="section-9.2-2">New entries in the range 0 to 23 ("1+0") are assigned by Standards Action.
New entries in the ranges 24 to 255 ("1+1") and 256 to 32767 (lower
half of "1+2") are assigned by Specification
Required.  New entries in the range 32768 to 18446744073709551615
(upper half of "1+2", "1+4", and "1+8") are
assigned by First Come First Served. The template for registration
requests is:<a href="#section-9.2-2" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-9.2-3.1">Data item<a href="#section-9.2-3.1" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-9.2-3.2">Semantics (short form)<a href="#section-9.2-3.2" class="pilcrow">¶</a>
</li>
        </ul>
<p id="section-9.2-4">In addition, First Come First Served requests should include:<a href="#section-9.2-4" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-9.2-5.1">Point of contact<a href="#section-9.2-5.1" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-9.2-5.2">Description of semantics (URL) -- This description is
optional; the URL can point to something like an Internet-Draft or a
web page.<a href="#section-9.2-5.2" class="pilcrow">¶</a>
</li>
        </ul>
<p id="section-9.2-6">Applicants exercising the First Come First Served range and making
a suggestion for a tag number that is not representable in 32 bits
(i.e., larger than 4294967295)
should be aware that this could reduce interoperability with
implementations that do not support 64-bit numbers.<a href="#section-9.2-6" class="pilcrow">¶</a></p>
</section>
</div>
<div id="media-type-mime-type">
<section id="section-9.3">
        <h3 id="name-media-types-registry">
<a href="#section-9.3" class="section-number selfRef">9.3. </a><a href="#name-media-types-registry" class="section-name selfRef">Media Types Registry</a>
        </h3>
<p id="section-9.3-1">The Internet media type <span>[<a href="#RFC6838" class="xref">RFC6838</a>]</span> ("MIME type") for a single encoded CBOR data
item is "application/cbor" as defined in the "Media Types" registry <span>[<a href="#IANA.media-types" class="xref">IANA.media-types</a>]</span>:<a href="#section-9.3-1" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-9.3-2">
          <dt id="section-9.3-2.1">Type name:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.2">application<a href="#section-9.3-2.2" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.3">Subtype name:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.4">cbor<a href="#section-9.3-2.4" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.5">Required parameters:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.6">n/a<a href="#section-9.3-2.6" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.7">Optional parameters:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.8">n/a<a href="#section-9.3-2.8" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.9">Encoding considerations:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.10">Binary<a href="#section-9.3-2.10" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.11">Security considerations:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.12">See <a href="#securitycons" class="xref">Section 10</a> of RFC 8949.<a href="#section-9.3-2.12" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.13">Interoperability considerations:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.14">n/a<a href="#section-9.3-2.14" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.15">Published specification:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.16">RFC 8949<a href="#section-9.3-2.16" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.17">Applications that use this media type:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.18">Many<a href="#section-9.3-2.18" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.19">Additional information:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.20">
            <p id="section-9.3-2.20.1"><br></p>
<span class="break"></span><dl class="dlParallel dlCompact" id="section-9.3-2.20.2">
              <dt id="section-9.3-2.20.2.1">Magic number(s):</dt>
              <dd style="margin-left: 1.5em" id="section-9.3-2.20.2.2"> n/a<a href="#section-9.3-2.20.2.2" class="pilcrow">¶</a>
</dd>
              <dd class="break"></dd>
<dt id="section-9.3-2.20.2.3">File extension(s):</dt>
              <dd style="margin-left: 1.5em" id="section-9.3-2.20.2.4"> .cbor<a href="#section-9.3-2.20.2.4" class="pilcrow">¶</a>
</dd>
              <dd class="break"></dd>
<dt id="section-9.3-2.20.2.5">Macintosh file type code(s):</dt>
              <dd style="margin-left: 1.5em" id="section-9.3-2.20.2.6">n/a<a href="#section-9.3-2.20.2.6" class="pilcrow">¶</a>
</dd>
            <dd class="break"></dd>
</dl>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.21">Person &amp; email address to contact for further information:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.22">IETF CBOR Working Group (cbor@ietf.org) or IETF
          Applications and Real-Time Area (art@ietf.org)<a href="#section-9.3-2.22" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.23">Intended usage:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.24">COMMON<a href="#section-9.3-2.24" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.25">Restrictions on usage:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.26">none<a href="#section-9.3-2.26" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.27">Author:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.28">IETF CBOR Working Group (cbor@ietf.org)<a href="#section-9.3-2.28" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.3-2.29">Change controller:</dt>
          <dd style="margin-left: 1.5em" id="section-9.3-2.30">The IESG (iesg@ietf.org)<a href="#section-9.3-2.30" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
</dl>
</section>
</div>
<div id="coap-content-format">
<section id="section-9.4">
        <h3 id="name-coap-content-format-registr">
<a href="#section-9.4" class="section-number selfRef">9.4. </a><a href="#name-coap-content-format-registr" class="section-name selfRef">CoAP Content-Format Registry</a>
        </h3>
<p id="section-9.4-1">The CoAP Content-Format for CBOR has been registered in the "CoAP
        Content-Formats" subregistry within the "Constrained RESTful
        Environments (CoRE) Parameters" registry <span>[<a href="#IANA.core-parameters" class="xref">IANA.core-parameters</a>]</span>:<a href="#section-9.4-1" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-9.4-2">
          <dt id="section-9.4-2.1">Media Type:</dt>
          <dd style="margin-left: 1.5em" id="section-9.4-2.2">application/cbor<a href="#section-9.4-2.2" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.4-2.3">Encoding:</dt>
          <dd style="margin-left: 1.5em" id="section-9.4-2.4">-<a href="#section-9.4-2.4" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.4-2.5">ID:</dt>
          <dd style="margin-left: 1.5em" id="section-9.4-2.6">60<a href="#section-9.4-2.6" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.4-2.7">Reference:</dt>
          <dd style="margin-left: 1.5em" id="section-9.4-2.8">RFC 8949<a href="#section-9.4-2.8" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
</dl>
</section>
</div>
<div id="the-cbor-structured-syntax-suffix-registration">
<section id="section-9.5">
        <h3 id="name-structured-syntax-suffix-re">
<a href="#section-9.5" class="section-number selfRef">9.5. </a><a href="#name-structured-syntax-suffix-re" class="section-name selfRef">Structured Syntax Suffix Registry</a>
        </h3>
<p id="section-9.5-1">The structured syntax suffix <span>[<a href="#RFC6838" class="xref">RFC6838</a>]</span> for media types based on a single
        encoded CBOR data item is +cbor, which IANA has registered in the
 "Structured Syntax Suffixes" registry <span>[<a href="#IANA.structured-suffix" class="xref">IANA.structured-suffix</a>]</span>:<a href="#section-9.5-1" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-9.5-2">
          <dt id="section-9.5-2.1">Name:</dt>
          <dd style="margin-left: 1.5em" id="section-9.5-2.2">Concise Binary Object Representation (CBOR)<a href="#section-9.5-2.2" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.5-2.3">+suffix:</dt>
          <dd style="margin-left: 1.5em" id="section-9.5-2.4">+cbor<a href="#section-9.5-2.4" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.5-2.5">References:</dt>
          <dd style="margin-left: 1.5em" id="section-9.5-2.6">RFC 8949<a href="#section-9.5-2.6" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.5-2.7">Encoding Considerations:</dt>
          <dd style="margin-left: 1.5em" id="section-9.5-2.8">CBOR is a binary format.<a href="#section-9.5-2.8" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.5-2.9">Interoperability Considerations:</dt>
          <dd style="margin-left: 1.5em" id="section-9.5-2.10">n/a<a href="#section-9.5-2.10" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.5-2.11">Fragment Identifier Considerations:</dt>
          <dd style="margin-left: 1.5em" id="section-9.5-2.12">
            <p id="section-9.5-2.12.1">
  The syntax and semantics of fragment identifiers specified for
+cbor <span class="bcp14">SHOULD</span> be as specified for "application/cbor".  (At
publication of RFC 8949, there is no fragment identification
syntax defined for "application/cbor".)<a href="#section-9.5-2.12.1" class="pilcrow">¶</a></p>
<p id="section-9.5-2.12.2">The syntax and semantics for fragment identifiers for a specific
"xxx/yyy+cbor" <span class="bcp14">SHOULD</span> be processed as follows:<a href="#section-9.5-2.12.2" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-9.5-2.12.3.1">For cases defined in +cbor, where the fragment identifier resolves
per the +cbor rules, then process as specified in +cbor.<a href="#section-9.5-2.12.3.1" class="pilcrow">¶</a>
</li>
              <li class="normal" id="section-9.5-2.12.3.2">For cases defined in +cbor, where the fragment identifier does
not resolve per the +cbor rules, then process as specified in
"xxx/yyy+cbor".<a href="#section-9.5-2.12.3.2" class="pilcrow">¶</a>
</li>
              <li class="normal" id="section-9.5-2.12.3.3">For cases not defined in +cbor, then process as specified in
"xxx/yyy+cbor".<a href="#section-9.5-2.12.3.3" class="pilcrow">¶</a>
</li>
            </ul>
</dd>
          <dd class="break"></dd>
<dt id="section-9.5-2.13">Security Considerations:</dt>
          <dd style="margin-left: 1.5em" id="section-9.5-2.14">See <a href="#securitycons" class="xref">Section 10</a> of RFC 8949.<a href="#section-9.5-2.14" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.5-2.15">Contact:</dt>
          <dd style="margin-left: 1.5em" id="section-9.5-2.16"> IETF CBOR Working Group (cbor@ietf.org) or
IETF Applications and Real-Time Area (art@ietf.org)<a href="#section-9.5-2.16" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-9.5-2.17">Author/Change Controller:</dt>
          <dd style="margin-left: 1.5em" id="section-9.5-2.18">IETF<a href="#section-9.5-2.18" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
</dl>
</section>
</div>
</section>
</div>
<div id="securitycons">
<section id="section-10">
      <h2 id="name-security-considerations">
<a href="#section-10" class="section-number selfRef">10. </a><a href="#name-security-considerations" class="section-name selfRef">Security Considerations</a>
      </h2>
<p id="section-10-1">A network-facing application can exhibit vulnerabilities in its
processing logic for incoming data. Complex parsers are well known as
a likely source of such vulnerabilities, such as the ability to
remotely crash a node, or even remotely execute arbitrary code on it.
CBOR attempts to narrow the opportunities for introducing such
vulnerabilities by reducing parser complexity, by giving the entire
range of encodable values a meaning where possible.<a href="#section-10-1" class="pilcrow">¶</a></p>
<p id="section-10-2">Because CBOR decoders are often used as a first step in processing
unvalidated input, they need to be fully prepared for all types of
hostile input that may be designed to corrupt, overrun, or achieve control
of the system decoding the CBOR data item. A CBOR decoder needs to
assume that all input may be hostile even if it has been checked by a
firewall, has come over a secure channel such as TLS, is encrypted or
signed,
or has come from some other source that is presumed trusted.<a href="#section-10-2" class="pilcrow">¶</a></p>
<p id="section-10-3"><a href="#preferred" class="xref">Section 4.1</a> gives examples of limitations in interoperability when using a
constrained CBOR decoder with input from a CBOR encoder that uses a
non-preferred serialization. When a single data item is consumed both by such a
constrained decoder and a full decoder, it can lead to security issues that can
be exploited by an attacker who can inject or manipulate content.<a href="#section-10-3" class="pilcrow">¶</a></p>
<p id="section-10-4">As discussed throughout this document, there are many values that can be
considered "equivalent" in some circumstances and "not equivalent" in others. As
just one example, the numeric value for the number "one" might be expressed as
an integer or a bignum. A system interpreting CBOR input might accept either
form for the number "one", or might reject one (or both) forms. Such acceptance
or rejection can have security implications in the program that is using the
interpreted input.<a href="#section-10-4" class="pilcrow">¶</a></p>
<p id="section-10-5">Hostile input may be constructed to overrun buffers, to overflow or
underflow integer arithmetic, or to cause other decoding disruption.  CBOR
data items might have lengths or sizes that are intentionally
extremely large or too short.
Resource exhaustion attacks might attempt to lure a decoder into
allocating very big data items (strings, arrays, maps, or even
arbitrary precision numbers) or exhaust the
stack depth by setting up deeply nested items.  Decoders need to have
appropriate resource management to mitigate these attacks.  (Items for
which very large sizes are given can also attempt to exploit integer
overflow vulnerabilities.)<a href="#section-10-5" class="pilcrow">¶</a></p>
<p id="section-10-6">A CBOR decoder, by definition, only accepts well-formed CBOR; this is
the first step to its robustness.  Input that is not well-formed CBOR
causes no further processing from the point where the lack of
well-formedness was detected.  If possible, any data decoded up to
this point should have no impact on the application using the CBOR
decoder.<a href="#section-10-6" class="pilcrow">¶</a></p>
<p id="section-10-7">In addition to ascertaining well-formedness, a CBOR decoder might also
perform validity checks on the CBOR data.  Alternatively, it can leave
those checks to the application using the decoder.  This choice needs
to be clearly documented in the decoder.  Beyond the validity at the CBOR level, an
application also needs to ascertain that the input is in alignment
with the application protocol that is serialized in CBOR.<a href="#section-10-7" class="pilcrow">¶</a></p>
<p id="section-10-8">The input check itself may consume resources.  This is usually linear
in the size of the input, which means that an attacker has to spend
resources that are commensurate to the resources spent by the defender
on input validation.
However, an attacker might be able to craft inputs that will take longer for a
target decoder to process than for the attacker to produce.
Processing for arbitrary-precision numbers may
exceed linear effort.  Also, some hash-table implementations that are
used by decoders to build in-memory representations of maps can be
attacked to spend quadratic effort, unless a secret key
(see Section 7 of <span>[<a href="#SIPHASH_LNCS" class="xref">SIPHASH_LNCS</a>]</span>, also <span>[<a href="#SIPHASH_OPEN" class="xref">SIPHASH_OPEN</a>]</span>) or some other mitigation is employed.
Such superlinear efforts can be
exploited by an attacker to exhaust resources at or before the input
validator; they therefore need to be avoided in a CBOR decoder
implementation.  Note that tag number definitions and their implementations
can add security considerations of this kind; this should then be
discussed in the security considerations of the tag number definition.<a href="#section-10-8" class="pilcrow">¶</a></p>
<p id="section-10-9">CBOR encoders do not receive input directly from the network and are
thus not directly attackable in the same way as CBOR decoders.
However, CBOR encoders often have an API that
takes input from another level in the implementation and can be
attacked through that API. The design and implementation of that API
should assume the behavior of its caller may be based on hostile input
or on coding mistakes. It should check inputs for buffer overruns,
overflow and underflow of integer arithmetic, and other such errors
that are aimed to disrupt the encoder.<a href="#section-10-9" class="pilcrow">¶</a></p>
<p id="section-10-10">Protocols should be defined in
such a way that potential multiple interpretations are reliably
reduced to a single interpretation.  For example, an attacker could make use of
invalid input such as duplicate keys in maps, or exploit different
precision in processing numbers to make one application base its
decisions on a different interpretation than the one that will be used
by a second application.  To facilitate consistent interpretation,
encoder and decoder implementations should
provide a validity-checking mode of operation
(<a href="#validity-checking" class="xref">Section 5.4</a>).  Note, however, that a generic decoder cannot
know about all requirements that an application poses on its input
data; it is therefore not relieving the application from performing its
own input checking.  Also, since the set of defined tag numbers
evolves, the application may employ a tag number that is not yet
supported for validity checking by the generic decoder it uses.  Generic
decoders therefore need to document which tag numbers
they support and what validity checking they provide for those 
tag numbers as well as for basic CBOR (UTF-8 checking, duplicate map
key checking).<a href="#section-10-10" class="pilcrow">¶</a></p>
<p id="section-10-11"><a href="#bignums" class="xref">Section 3.4.3</a> notes that using the non-preferred choice of a bignum
representation instead of a basic integer for encoding a number is not intended
to have application semantics, but it can have such semantics if an application
receiving CBOR data is using a decoder in the basic generic data model. This
disparity causes a security issue if the two sets of semantics differ. Thus,
applications using CBOR need to specify the data model that they are using for
each use of CBOR data.<a href="#section-10-11" class="pilcrow">¶</a></p>
<p id="section-10-12">It is common to convert CBOR data to other formats. In many cases, CBOR has more
expressive types than other formats; this is particularly true for the
common conversion to JSON. The loss of type information can cause security
issues for the systems that are processing the less-expressive data.<a href="#section-10-12" class="pilcrow">¶</a></p>
<p id="section-10-13"><a href="#converting-from-json" class="xref">Section 6.2</a> describes a possibly common usage scenario of
converting between CBOR and JSON that could allow an attack if the attacker knows
that the application is performing the conversion.<a href="#section-10-13" class="pilcrow">¶</a></p>
<p id="section-10-14">Security considerations for the use of base16 and base64 from <span>[<a href="#RFC4648" class="xref">RFC4648</a>]</span>, and the use
of UTF-8 from <span>[<a href="#RFC3629" class="xref">RFC3629</a>]</span>, are relevant to CBOR as well.<a href="#section-10-14" class="pilcrow">¶</a></p>
</section>
</div>
<section id="section-11">
      <h2 id="name-references">
<a href="#section-11" class="section-number selfRef">11. </a><a href="#name-references" class="section-name selfRef">References</a>
      </h2>
<section id="section-11.1">
        <h3 id="name-normative-references">
<a href="#section-11.1" class="section-number selfRef">11.1. </a><a href="#name-normative-references" class="section-name selfRef">Normative References</a>
        </h3>
<dl class="references">
<dt id="C">[C]</dt>
        <dd>
<span class="refAuthor">International Organization for Standardization</span>, <span class="refTitle">"Information technology - Programming languages - C"</span>, <span class="refContent">Fourth Edition</span>, <span class="seriesInfo">ISO/IEC 9899:2018</span>, <time datetime="2018-06" class="refDate">June 2018</time>, <span>&lt;<a href="https://www.iso.org/standard/74528.html">https://www.iso.org/standard/74528.html</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Cplusplus20">[Cplusplus20]</dt>
        <dd>
<span class="refAuthor">International Organization for Standardization</span>, <span class="refTitle">"Programming languages - C++"</span>, <span class="refContent">Sixth Edition</span>, <span class="seriesInfo">ISO/IEC DIS 14882</span>, <span class="seriesInfo">ISO/IEC ISO/IEC JTC1 SC22 WG21 N 4860</span>, <time datetime="2020-03" class="refDate">March 2020</time>, <span>&lt;<a href="https://isocpp.org/files/papers/N4860.pdf">https://isocpp.org/files/papers/N4860.pdf</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="IEEE754">[IEEE754]</dt>
        <dd>
<span class="refAuthor">IEEE</span>, <span class="refTitle">"IEEE Standard for Floating-Point Arithmetic"</span>, <span class="seriesInfo">IEEE Std 754-2019</span>, <span class="seriesInfo">DOI 10.1109/IEEESTD.2019.8766229</span>, <span>&lt;<a href="https://ieeexplore.ieee.org/document/8766229">https://ieeexplore.ieee.org/document/8766229</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC2045">[RFC2045]</dt>
        <dd>
<span class="refAuthor">Freed, N.</span><span class="refAuthor"> and N. Borenstein</span>, <span class="refTitle">"Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies"</span>, <span class="seriesInfo">RFC 2045</span>, <span class="seriesInfo">DOI 10.17487/RFC2045</span>, <time datetime="1996-11" class="refDate">November 1996</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc2045">https://www.rfc-editor.org/info/rfc2045</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC2119">[RFC2119]</dt>
        <dd>
<span class="refAuthor">Bradner, S.</span>, <span class="refTitle">"Key words for use in RFCs to Indicate Requirement Levels"</span>, <span class="seriesInfo">BCP 14</span>, <span class="seriesInfo">RFC 2119</span>, <span class="seriesInfo">DOI 10.17487/RFC2119</span>, <time datetime="1997-03" class="refDate">March 1997</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc2119">https://www.rfc-editor.org/info/rfc2119</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC3339">[RFC3339]</dt>
        <dd>
<span class="refAuthor">Klyne, G.</span><span class="refAuthor"> and C. Newman</span>, <span class="refTitle">"Date and Time on the Internet: Timestamps"</span>, <span class="seriesInfo">RFC 3339</span>, <span class="seriesInfo">DOI 10.17487/RFC3339</span>, <time datetime="2002-07" class="refDate">July 2002</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc3339">https://www.rfc-editor.org/info/rfc3339</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC3629">[RFC3629]</dt>
        <dd>
<span class="refAuthor">Yergeau, F.</span>, <span class="refTitle">"UTF-8, a transformation format of ISO 10646"</span>, <span class="seriesInfo">STD 63</span>, <span class="seriesInfo">RFC 3629</span>, <span class="seriesInfo">DOI 10.17487/RFC3629</span>, <time datetime="2003-11" class="refDate">November 2003</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc3629">https://www.rfc-editor.org/info/rfc3629</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC3986">[RFC3986]</dt>
        <dd>
<span class="refAuthor">Berners-Lee, T.</span><span class="refAuthor">, Fielding, R.</span><span class="refAuthor">, and L. Masinter</span>, <span class="refTitle">"Uniform Resource Identifier (URI): Generic Syntax"</span>, <span class="seriesInfo">STD 66</span>, <span class="seriesInfo">RFC 3986</span>, <span class="seriesInfo">DOI 10.17487/RFC3986</span>, <time datetime="2005-01" class="refDate">January 2005</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc3986">https://www.rfc-editor.org/info/rfc3986</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC4287">[RFC4287]</dt>
        <dd>
<span class="refAuthor">Nottingham, M., Ed.</span><span class="refAuthor"> and R. Sayre, Ed.</span>, <span class="refTitle">"The Atom Syndication Format"</span>, <span class="seriesInfo">RFC 4287</span>, <span class="seriesInfo">DOI 10.17487/RFC4287</span>, <time datetime="2005-12" class="refDate">December 2005</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc4287">https://www.rfc-editor.org/info/rfc4287</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC4648">[RFC4648]</dt>
        <dd>
<span class="refAuthor">Josefsson, S.</span>, <span class="refTitle">"The Base16, Base32, and Base64 Data Encodings"</span>, <span class="seriesInfo">RFC 4648</span>, <span class="seriesInfo">DOI 10.17487/RFC4648</span>, <time datetime="2006-10" class="refDate">October 2006</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc4648">https://www.rfc-editor.org/info/rfc4648</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC8126">[RFC8126]</dt>
        <dd>
<span class="refAuthor">Cotton, M.</span><span class="refAuthor">, Leiba, B.</span><span class="refAuthor">, and T. Narten</span>, <span class="refTitle">"Guidelines for Writing an IANA Considerations Section in RFCs"</span>, <span class="seriesInfo">BCP 26</span>, <span class="seriesInfo">RFC 8126</span>, <span class="seriesInfo">DOI 10.17487/RFC8126</span>, <time datetime="2017-06" class="refDate">June 2017</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc8126">https://www.rfc-editor.org/info/rfc8126</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC8174">[RFC8174]</dt>
        <dd>
<span class="refAuthor">Leiba, B.</span>, <span class="refTitle">"Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words"</span>, <span class="seriesInfo">BCP 14</span>, <span class="seriesInfo">RFC 8174</span>, <span class="seriesInfo">DOI 10.17487/RFC8174</span>, <time datetime="2017-05" class="refDate">May 2017</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc8174">https://www.rfc-editor.org/info/rfc8174</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="TIME_T">[TIME_T]</dt>
      <dd>
<span class="refAuthor">The Open Group</span>, <span class="refTitle">"The Open Group Base Specifications"</span>, <span class="refContent">Section 4.16, 'Seconds Since the Epoch'</span>, <span class="refContent">Issue 7, 2018 Edition</span>, <span class="seriesInfo">IEEE Std 1003.1</span>, <time datetime="2018" class="refDate">2018</time>, <span>&lt;<a href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16">https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16</a>&gt;</span>. </dd>
<dd class="break"></dd>
</dl>
</section>
<section id="section-11.2">
        <h3 id="name-informative-references">
<a href="#section-11.2" class="section-number selfRef">11.2. </a><a href="#name-informative-references" class="section-name selfRef">Informative References</a>
        </h3>
<dl class="references">
<dt id="ASN.1">[ASN.1]</dt>
        <dd>
<span class="refAuthor">International Telecommunication Union</span>, <span class="refTitle">"Information Technology - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER)"</span>, <span class="seriesInfo">ITU-T Recommendation X.690</span>, <time datetime="2015" class="refDate">2015</time>, <span>&lt;<a href="https://www.itu.int/rec/T-REC-X.690-201508-I/en">https://www.itu.int/rec/T-REC-X.690-201508-I/en</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="BSON">[BSON]</dt>
        <dd>
<span class="refAuthor">Various</span>, <span class="refTitle">"BSON - Binary JSON"</span>, <span>&lt;<a href="http://bsonspec.org/">http://bsonspec.org/</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="I-D.bormann-cbor-notable-tags">[CBOR-TAGS]</dt>
        <dd>
<span class="refAuthor">Bormann, C.</span>, <span class="refTitle">"Notable CBOR Tags"</span>, <span class="refContent">Work in Progress</span>, <span class="seriesInfo">Internet-Draft, draft-bormann-cbor-notable-tags-02</span>, <time datetime="2020-06-25" class="refDate">25 June 2020</time>, <span>&lt;<a href="https://tools.ietf.org/html/draft-bormann-cbor-notable-tags-02">https://tools.ietf.org/html/draft-bormann-cbor-notable-tags-02</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="ECMA262">[ECMA262]</dt>
        <dd>
<span class="refAuthor">Ecma International</span>, <span class="refTitle">"ECMAScript 2020 Language Specification"</span>, <span class="refContent">Standard ECMA-262, 11th Edition</span>, <time datetime="2020-06" class="refDate">June 2020</time>, <span>&lt;<a href="https://www.ecma-international.org/publications/standards/Ecma-262.htm">https://www.ecma-international.org/publications/standards/Ecma-262.htm</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Err3764">[Err3764]</dt>
        <dd>
<span class="refAuthor">RFC Errata</span>, <span class="refTitle">Erratum ID 3764</span>, <span class="refContent">RFC 7049</span>, <span>&lt;<a href="https://www.rfc-editor.org/errata/eid3764">https://www.rfc-editor.org/errata/eid3764</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Err3770">[Err3770]</dt>
        <dd>
<span class="refAuthor">RFC Errata</span>, <span class="refTitle">Erratum ID 3770</span>, <span class="refContent">RFC 7049</span>, <span>&lt;<a href="https://www.rfc-editor.org/errata/eid3770">https://www.rfc-editor.org/errata/eid3770</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Err4294">[Err4294]</dt>
        <dd>
<span class="refAuthor">RFC Errata</span>, <span class="refTitle">Erratum ID 4294</span>, <span class="refContent">RFC 7049</span>, <span>&lt;<a href="https://www.rfc-editor.org/errata/eid4294">https://www.rfc-editor.org/errata/eid4294</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Err4409">[Err4409]</dt>
        <dd>
<span class="refAuthor">RFC Errata</span>, <span class="refTitle">Erratum ID 4409</span>, <span class="refContent">RFC 7049</span>, <span>&lt;<a href="https://www.rfc-editor.org/errata/eid4409">https://www.rfc-editor.org/errata/eid4409</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Err4963">[Err4963]</dt>
        <dd>
<span class="refAuthor">RFC Errata</span>, <span class="refTitle">Erratum ID 4963</span>, <span class="refContent">RFC 7049</span>, <span>&lt;<a href="https://www.rfc-editor.org/errata/eid4963">https://www.rfc-editor.org/errata/eid4963</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Err4964">[Err4964]</dt>
        <dd>
<span class="refAuthor">RFC Errata</span>, <span class="refTitle">Erratum ID 4964</span>, <span class="refContent">RFC 7049</span>, <span>&lt;<a href="https://www.rfc-editor.org/errata/eid4964">https://www.rfc-editor.org/errata/eid4964</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Err5434">[Err5434]</dt>
        <dd>
<span class="refAuthor">RFC Errata</span>, <span class="refTitle">Erratum ID 5434</span>, <span class="refContent">RFC 7049</span>, <span>&lt;<a href="https://www.rfc-editor.org/errata/eid5434">https://www.rfc-editor.org/errata/eid5434</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Err5763">[Err5763]</dt>
        <dd>
<span class="refAuthor">RFC Errata</span>, <span class="refTitle">Erratum ID 5763</span>, <span class="refContent">RFC 7049</span>, <span>&lt;<a href="https://www.rfc-editor.org/errata/eid5763">https://www.rfc-editor.org/errata/eid5763</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="Err5917">[Err5917]</dt>
        <dd>
<span class="refAuthor">RFC Errata</span>, <span class="refTitle">Erratum ID 5917</span>, <span class="refContent">RFC 7049</span>, <span>&lt;<a href="https://www.rfc-editor.org/errata/eid5917">https://www.rfc-editor.org/errata/eid5917</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="IANA.cbor-simple-values">[IANA.cbor-simple-values]</dt>
        <dd>
<span class="refAuthor">IANA</span>, <span class="refTitle">"Concise Binary Object Representation (CBOR) Simple Values"</span>, <span>&lt;<a href="https://www.iana.org/assignments/cbor-simple-values">https://www.iana.org/assignments/cbor-simple-values</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="IANA.cbor-tags">[IANA.cbor-tags]</dt>
        <dd>
<span class="refAuthor">IANA</span>, <span class="refTitle">"Concise Binary Object Representation (CBOR) Tags"</span>, <span>&lt;<a href="https://www.iana.org/assignments/cbor-tags">https://www.iana.org/assignments/cbor-tags</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="IANA.core-parameters">[IANA.core-parameters]</dt>
        <dd>
<span class="refAuthor">IANA</span>, <span class="refTitle">"Constrained RESTful Environments (CoRE) Parameters"</span>, <span>&lt;<a href="https://www.iana.org/assignments/core-parameters">https://www.iana.org/assignments/core-parameters</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="IANA.media-types">[IANA.media-types]</dt>
        <dd>
<span class="refAuthor">IANA</span>, <span class="refTitle">"Media Types"</span>, <span>&lt;<a href="https://www.iana.org/assignments/media-types">https://www.iana.org/assignments/media-types</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="IANA.structured-suffix">[IANA.structured-suffix]</dt>
        <dd>
<span class="refAuthor">IANA</span>, <span class="refTitle">"Structured Syntax Suffixes"</span>, <span>&lt;<a href="https://www.iana.org/assignments/media-type-structured-suffix">https://www.iana.org/assignments/media-type-structured-suffix</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="MessagePack">[MessagePack]</dt>
        <dd>
<span class="refAuthor">Furuhashi, S.</span>, <span class="refTitle">"MessagePack"</span>, <span>&lt;<a href="https://msgpack.org/">https://msgpack.org/</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="PCRE">[PCRE]</dt>
        <dd>
<span class="refAuthor">Hazel, P.</span>, <span class="refTitle">"PCRE - Perl Compatible Regular Expressions"</span>, <span>&lt;<a href="https://www.pcre.org/">https://www.pcre.org/</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC0713">[RFC0713]</dt>
        <dd>
<span class="refAuthor">Haverty, J.</span>, <span class="refTitle">"MSDTP-Message Services Data Transmission Protocol"</span>, <span class="seriesInfo">RFC 713</span>, <span class="seriesInfo">DOI 10.17487/RFC0713</span>, <time datetime="1976-04" class="refDate">April 1976</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc713">https://www.rfc-editor.org/info/rfc713</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC6838">[RFC6838]</dt>
        <dd>
<span class="refAuthor">Freed, N.</span><span class="refAuthor">, Klensin, J.</span><span class="refAuthor">, and T. Hansen</span>, <span class="refTitle">"Media Type Specifications and Registration Procedures"</span>, <span class="seriesInfo">BCP 13</span>, <span class="seriesInfo">RFC 6838</span>, <span class="seriesInfo">DOI 10.17487/RFC6838</span>, <time datetime="2013-01" class="refDate">January 2013</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc6838">https://www.rfc-editor.org/info/rfc6838</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC7049">[RFC7049]</dt>
        <dd>
<span class="refAuthor">Bormann, C.</span><span class="refAuthor"> and P. Hoffman</span>, <span class="refTitle">"Concise Binary Object Representation (CBOR)"</span>, <span class="seriesInfo">RFC 7049</span>, <span class="seriesInfo">DOI 10.17487/RFC7049</span>, <time datetime="2013-10" class="refDate">October 2013</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc7049">https://www.rfc-editor.org/info/rfc7049</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC7228">[RFC7228]</dt>
        <dd>
<span class="refAuthor">Bormann, C.</span><span class="refAuthor">, Ersue, M.</span><span class="refAuthor">, and A. Keranen</span>, <span class="refTitle">"Terminology for Constrained-Node Networks"</span>, <span class="seriesInfo">RFC 7228</span>, <span class="seriesInfo">DOI 10.17487/RFC7228</span>, <time datetime="2014-05" class="refDate">May 2014</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc7228">https://www.rfc-editor.org/info/rfc7228</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC7493">[RFC7493]</dt>
        <dd>
<span class="refAuthor">Bray, T., Ed.</span>, <span class="refTitle">"The I-JSON Message Format"</span>, <span class="seriesInfo">RFC 7493</span>, <span class="seriesInfo">DOI 10.17487/RFC7493</span>, <time datetime="2015-03" class="refDate">March 2015</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc7493">https://www.rfc-editor.org/info/rfc7493</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC7991">[RFC7991]</dt>
        <dd>
<span class="refAuthor">Hoffman, P.</span>, <span class="refTitle">"The "xml2rfc" Version 3 Vocabulary"</span>, <span class="seriesInfo">RFC 7991</span>, <span class="seriesInfo">DOI 10.17487/RFC7991</span>, <time datetime="2016-12" class="refDate">December 2016</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc7991">https://www.rfc-editor.org/info/rfc7991</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC8259">[RFC8259]</dt>
        <dd>
<span class="refAuthor">Bray, T., Ed.</span>, <span class="refTitle">"The JavaScript Object Notation (JSON) Data Interchange Format"</span>, <span class="seriesInfo">STD 90</span>, <span class="seriesInfo">RFC 8259</span>, <span class="seriesInfo">DOI 10.17487/RFC8259</span>, <time datetime="2017-12" class="refDate">December 2017</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc8259">https://www.rfc-editor.org/info/rfc8259</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC8610">[RFC8610]</dt>
        <dd>
<span class="refAuthor">Birkholz, H.</span><span class="refAuthor">, Vigano, C.</span><span class="refAuthor">, and C. Bormann</span>, <span class="refTitle">"Concise Data Definition Language (CDDL): A Notational Convention to Express Concise Binary Object Representation (CBOR) and JSON Data Structures"</span>, <span class="seriesInfo">RFC 8610</span>, <span class="seriesInfo">DOI 10.17487/RFC8610</span>, <time datetime="2019-06" class="refDate">June 2019</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc8610">https://www.rfc-editor.org/info/rfc8610</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC8618">[RFC8618]</dt>
        <dd>
<span class="refAuthor">Dickinson, J.</span><span class="refAuthor">, Hague, J.</span><span class="refAuthor">, Dickinson, S.</span><span class="refAuthor">, Manderson, T.</span><span class="refAuthor">, and J. Bond</span>, <span class="refTitle">"Compacted-DNS (C-DNS): A Format for DNS Packet Capture"</span>, <span class="seriesInfo">RFC 8618</span>, <span class="seriesInfo">DOI 10.17487/RFC8618</span>, <time datetime="2019-09" class="refDate">September 2019</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc8618">https://www.rfc-editor.org/info/rfc8618</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC8742">[RFC8742]</dt>
        <dd>
<span class="refAuthor">Bormann, C.</span>, <span class="refTitle">"Concise Binary Object Representation (CBOR) Sequences"</span>, <span class="seriesInfo">RFC 8742</span>, <span class="seriesInfo">DOI 10.17487/RFC8742</span>, <time datetime="2020-02" class="refDate">February 2020</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc8742">https://www.rfc-editor.org/info/rfc8742</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="RFC8746">[RFC8746]</dt>
        <dd>
<span class="refAuthor">Bormann, C., Ed.</span>, <span class="refTitle">"Concise Binary Object Representation (CBOR) Tags for Typed Arrays"</span>, <span class="seriesInfo">RFC 8746</span>, <span class="seriesInfo">DOI 10.17487/RFC8746</span>, <time datetime="2020-02" class="refDate">February 2020</time>, <span>&lt;<a href="https://www.rfc-editor.org/info/rfc8746">https://www.rfc-editor.org/info/rfc8746</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="SIPHASH_LNCS">[SIPHASH_LNCS]</dt>
        <dd>
<span class="refAuthor">Aumasson, J.</span><span class="refAuthor"> and D. Bernstein</span>, <span class="refTitle">"SipHash: A Fast Short-Input PRF"</span>, <span class="refContent">Progress in Cryptology - INDOCRYPT 2012, pp. 489-508</span>, <span class="seriesInfo">DOI 10.1007/978-3-642-34931-7_28</span>, <time datetime="2012" class="refDate">2012</time>, <span>&lt;<a href="https://doi.org/10.1007/978-3-642-34931-7_28">https://doi.org/10.1007/978-3-642-34931-7_28</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="SIPHASH_OPEN">[SIPHASH_OPEN]</dt>
        <dd>
<span class="refAuthor">Aumasson, J.</span><span class="refAuthor"> and D.J. Bernstein</span>, <span class="refTitle">"SipHash: a fast short-input PRF"</span>, <span>&lt;<a href="https://www.aumasson.jp/siphash/siphash.pdf">https://www.aumasson.jp/siphash/siphash.pdf</a>&gt;</span>. </dd>
<dd class="break"></dd>
<dt id="YAML">[YAML]</dt>
      <dd>
<span class="refAuthor">Ben-Kiki, O.</span><span class="refAuthor">, Evans, C.</span><span class="refAuthor">, and I.d. Net</span>, <span class="refTitle">"YAML Ain't Markup Language (YAML[TM]) Version 1.2"</span>, <span class="refContent">3rd Edition</span>, <time datetime="2009-10" class="refDate">October 2009</time>, <span>&lt;<a href="https://www.yaml.org/spec/1.2/spec.html">https://www.yaml.org/spec/1.2/spec.html</a>&gt;</span>. </dd>
<dd class="break"></dd>
</dl>
</section>
</section>
<div id="examples">
<section id="section-appendix.a">
      <h2 id="name-examples-of-encoded-cbor-da">
<a href="#section-appendix.a" class="section-number selfRef">Appendix A. </a><a href="#name-examples-of-encoded-cbor-da" class="section-name selfRef">Examples of Encoded CBOR Data Items</a>
      </h2>
<p id="section-appendix.a-1">The following table provides some CBOR-encoded values in hexadecimal
      (right column), together with diagnostic notation for these values (left
      column).  Note that the string "\u00fc" is one form of diagnostic
      notation for a UTF-8 string containing the single Unicode character <span class="unicode">U+00FC (LATIN SMALL LETTER U WITH DIAERESIS, "ü")</span>.  Similarly, "\u6c34" is a UTF-8 string in
      diagnostic notation with a single character <span class="unicode">U+6C34 (CJK UNIFIED IDEOGRAPH-6C34, "水")</span>, 
      often representing "water", and "\ud800\udd51" is a UTF-8 string
      in diagnostic notation with a single character <span class="unicode">U+10151 (GREEK ACROPHONIC ATTIC FIFTY STATERS, "𐅑")</span>.  (Note that all these single-character 
      strings could also be represented in native UTF-8 in diagnostic
      notation, just not if an ASCII-only specification is required.) 
      In the diagnostic notation provided for
      bignums, their intended numeric value is shown as a decimal number (such
      as 18446744073709551616) instead of a tagged byte string (such as
      2(h'010000000000000000')).<a href="#section-appendix.a-1" class="pilcrow">¶</a></p>
<span id="name-examples-of-encoded-cbor-dat"></span><div id="table_examples">
<table class="center" id="table-6">
        <caption>
<a href="#table-6" class="selfRef">Table 6</a>:
<a href="#name-examples-of-encoded-cbor-dat" class="selfRef">Examples of Encoded CBOR Data Items</a>
        </caption>
<thead>
          <tr>
            <th class="text-left" rowspan="1" colspan="1">Diagnostic</th>
            <th class="text-left" rowspan="1" colspan="1">Encoded</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0</td>
            <td class="text-left" rowspan="1" colspan="1">0x00</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1</td>
            <td class="text-left" rowspan="1" colspan="1">0x01</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">10</td>
            <td class="text-left" rowspan="1" colspan="1">0x0a</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">23</td>
            <td class="text-left" rowspan="1" colspan="1">0x17</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">24</td>
            <td class="text-left" rowspan="1" colspan="1">0x1818</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">25</td>
            <td class="text-left" rowspan="1" colspan="1">0x1819</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">100</td>
            <td class="text-left" rowspan="1" colspan="1">0x1864</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1000</td>
            <td class="text-left" rowspan="1" colspan="1">0x1903e8</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1000000</td>
            <td class="text-left" rowspan="1" colspan="1">0x1a000f4240</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1000000000000</td>
            <td class="text-left" rowspan="1" colspan="1">0x1b000000e8d4a51000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">18446744073709551615</td>
            <td class="text-left" rowspan="1" colspan="1">0x1bffffffffffffffff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">18446744073709551616</td>
            <td class="text-left" rowspan="1" colspan="1">0xc249010000000000000000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-18446744073709551616</td>
            <td class="text-left" rowspan="1" colspan="1">0x3bffffffffffffffff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-18446744073709551617</td>
            <td class="text-left" rowspan="1" colspan="1">0xc349010000000000000000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-1</td>
            <td class="text-left" rowspan="1" colspan="1">0x20</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-10</td>
            <td class="text-left" rowspan="1" colspan="1">0x29</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-100</td>
            <td class="text-left" rowspan="1" colspan="1">0x3863</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-1000</td>
            <td class="text-left" rowspan="1" colspan="1">0x3903e7</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0.0</td>
            <td class="text-left" rowspan="1" colspan="1">0xf90000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-0.0</td>
            <td class="text-left" rowspan="1" colspan="1">0xf98000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1.0</td>
            <td class="text-left" rowspan="1" colspan="1">0xf93c00</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1.1</td>
            <td class="text-left" rowspan="1" colspan="1">0xfb3ff199999999999a</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1.5</td>
            <td class="text-left" rowspan="1" colspan="1">0xf93e00</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">65504.0</td>
            <td class="text-left" rowspan="1" colspan="1">0xf97bff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">100000.0</td>
            <td class="text-left" rowspan="1" colspan="1">0xfa47c35000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">3.4028234663852886e+38</td>
            <td class="text-left" rowspan="1" colspan="1">0xfa7f7fffff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1.0e+300</td>
            <td class="text-left" rowspan="1" colspan="1">0xfb7e37e43c8800759c</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">5.960464477539063e-8</td>
            <td class="text-left" rowspan="1" colspan="1">0xf90001</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0.00006103515625</td>
            <td class="text-left" rowspan="1" colspan="1">0xf90400</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-4.0</td>
            <td class="text-left" rowspan="1" colspan="1">0xf9c400</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-4.1</td>
            <td class="text-left" rowspan="1" colspan="1">0xfbc010666666666666</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">Infinity</td>
            <td class="text-left" rowspan="1" colspan="1">0xf97c00</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">NaN</td>
            <td class="text-left" rowspan="1" colspan="1">0xf97e00</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-Infinity</td>
            <td class="text-left" rowspan="1" colspan="1">0xf9fc00</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">Infinity</td>
            <td class="text-left" rowspan="1" colspan="1">0xfa7f800000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">NaN</td>
            <td class="text-left" rowspan="1" colspan="1">0xfa7fc00000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-Infinity</td>
            <td class="text-left" rowspan="1" colspan="1">0xfaff800000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">Infinity</td>
            <td class="text-left" rowspan="1" colspan="1">0xfb7ff0000000000000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">NaN</td>
            <td class="text-left" rowspan="1" colspan="1">0xfb7ff8000000000000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">-Infinity</td>
            <td class="text-left" rowspan="1" colspan="1">0xfbfff0000000000000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">false</td>
            <td class="text-left" rowspan="1" colspan="1">0xf4</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">true</td>
            <td class="text-left" rowspan="1" colspan="1">0xf5</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">null</td>
            <td class="text-left" rowspan="1" colspan="1">0xf6</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">undefined</td>
            <td class="text-left" rowspan="1" colspan="1">0xf7</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">simple(16)</td>
            <td class="text-left" rowspan="1" colspan="1">0xf0</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">simple(255)</td>
            <td class="text-left" rowspan="1" colspan="1">0xf8ff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0("2013-03-21T20:04:00Z")</td>
            <td class="text-left" rowspan="1" colspan="1">0xc074323031332d30332d32315432303a 30343a30305a</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1(1363896240)</td>
            <td class="text-left" rowspan="1" colspan="1">0xc11a514b67b0</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">1(1363896240.5)</td>
            <td class="text-left" rowspan="1" colspan="1">0xc1fb41d452d9ec200000</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">23(h'01020304')</td>
            <td class="text-left" rowspan="1" colspan="1">0xd74401020304</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">24(h'6449455446')</td>
            <td class="text-left" rowspan="1" colspan="1">0xd818456449455446</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">32("http://www.example.com")</td>
            <td class="text-left" rowspan="1" colspan="1">0xd82076687474703a2f2f7777772e6578 616d706c652e636f6d</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">h''</td>
            <td class="text-left" rowspan="1" colspan="1">0x40</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">h'01020304'</td>
            <td class="text-left" rowspan="1" colspan="1">0x4401020304</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">""</td>
            <td class="text-left" rowspan="1" colspan="1">0x60</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">"a"</td>
            <td class="text-left" rowspan="1" colspan="1">0x6161</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">"IETF"</td>
            <td class="text-left" rowspan="1" colspan="1">0x6449455446</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">"\"\\"</td>
            <td class="text-left" rowspan="1" colspan="1">0x62225c</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">"\u00fc"</td>
            <td class="text-left" rowspan="1" colspan="1">0x62c3bc</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">"\u6c34"</td>
            <td class="text-left" rowspan="1" colspan="1">0x63e6b0b4</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">"\ud800\udd51"</td>
            <td class="text-left" rowspan="1" colspan="1">0x64f0908591</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[]</td>
            <td class="text-left" rowspan="1" colspan="1">0x80</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[1, 2, 3]</td>
            <td class="text-left" rowspan="1" colspan="1">0x83010203</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[1, [2, 3], [4, 5]]</td>
            <td class="text-left" rowspan="1" colspan="1">0x8301820203820405</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]</td>
            <td class="text-left" rowspan="1" colspan="1">0x98190102030405060708090a0b0c0d0e 0f101112131415161718181819</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">{}</td>
            <td class="text-left" rowspan="1" colspan="1">0xa0</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">{1: 2, 3: 4}</td>
            <td class="text-left" rowspan="1" colspan="1">0xa201020304</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">{"a": 1, "b": [2, 3]}</td>
            <td class="text-left" rowspan="1" colspan="1">0xa26161016162820203</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">["a", {"b": "c"}]</td>
            <td class="text-left" rowspan="1" colspan="1">0x826161a161626163</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">{"a": "A", "b": "B", "c": "C", "d": "D", "e": "E"}</td>
            <td class="text-left" rowspan="1" colspan="1">0xa5616161416162614261636143616461 4461656145</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">(_ h'0102', h'030405')</td>
            <td class="text-left" rowspan="1" colspan="1">0x5f42010243030405ff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">(_ "strea", "ming")</td>
            <td class="text-left" rowspan="1" colspan="1">0x7f657374726561646d696e67ff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[_ ]</td>
            <td class="text-left" rowspan="1" colspan="1">0x9fff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[_ 1, [2, 3], [_ 4, 5]]</td>
            <td class="text-left" rowspan="1" colspan="1">0x9f018202039f0405ffff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[_ 1, [2, 3], [4, 5]]</td>
            <td class="text-left" rowspan="1" colspan="1">0x9f01820203820405ff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[1, [2, 3], [_ 4, 5]]</td>
            <td class="text-left" rowspan="1" colspan="1">0x83018202039f0405ff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[1, [_ 2, 3], [4, 5]]</td>
            <td class="text-left" rowspan="1" colspan="1">0x83019f0203ff820405</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">[_ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]</td>
            <td class="text-left" rowspan="1" colspan="1">0x9f0102030405060708090a0b0c0d0e0f 101112131415161718181819ff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">{_ "a": 1, "b": [_ 2, 3]}</td>
            <td class="text-left" rowspan="1" colspan="1">0xbf61610161629f0203ffff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">["a", {_ "b": "c"}]</td>
            <td class="text-left" rowspan="1" colspan="1">0x826161bf61626163ff</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">{_ "Fun": true, "Amt": -2}</td>
            <td class="text-left" rowspan="1" colspan="1">0xbf6346756ef563416d7421ff</td>
          </tr>
        </tbody>
      </table>
</div>
</section>
</div>
<div id="jump-table">
<section id="section-appendix.b">
      <h2 id="name-jump-table-for-initial-byte">
<a href="#section-appendix.b" class="section-number selfRef">Appendix B. </a><a href="#name-jump-table-for-initial-byte" class="section-name selfRef">Jump Table for Initial Byte</a>
      </h2>
<p id="section-appendix.b-1">For brevity, this jump table does not show initial bytes that are
reserved for future extension. It also only shows a selection of the
initial bytes that can be used for optional features.  (All
unsigned integers are in network byte order.)<a href="#section-appendix.b-1" class="pilcrow">¶</a></p>
<span id="name-jump-table-for-initial-byte-2"></span><div id="jumptable">
<table class="center" id="table-7">
        <caption>
<a href="#table-7" class="selfRef">Table 7</a>:
<a href="#name-jump-table-for-initial-byte-2" class="selfRef">Jump Table for Initial Byte</a>
        </caption>
<thead>
          <tr>
            <th class="text-left" rowspan="1" colspan="1">Byte</th>
            <th class="text-left" rowspan="1" colspan="1">Structure/Semantics</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x00..0x17</td>
            <td class="text-left" rowspan="1" colspan="1">unsigned integer 0x00..0x17 (0..23)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x18</td>
            <td class="text-left" rowspan="1" colspan="1">unsigned integer (one-byte uint8_t follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x19</td>
            <td class="text-left" rowspan="1" colspan="1">unsigned integer (two-byte uint16_t follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x1a</td>
            <td class="text-left" rowspan="1" colspan="1">unsigned integer (four-byte uint32_t follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x1b</td>
            <td class="text-left" rowspan="1" colspan="1">unsigned integer (eight-byte uint64_t follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x20..0x37</td>
            <td class="text-left" rowspan="1" colspan="1">negative integer -1-0x00..-1-0x17 (-1..-24)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x38</td>
            <td class="text-left" rowspan="1" colspan="1">negative integer -1-n (one-byte uint8_t for n follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x39</td>
            <td class="text-left" rowspan="1" colspan="1">negative integer -1-n (two-byte uint16_t for n follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x3a</td>
            <td class="text-left" rowspan="1" colspan="1">negative integer -1-n (four-byte uint32_t for n follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x3b</td>
            <td class="text-left" rowspan="1" colspan="1">negative integer -1-n (eight-byte uint64_t for n follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x40..0x57</td>
            <td class="text-left" rowspan="1" colspan="1">byte string (0x00..0x17 bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x58</td>
            <td class="text-left" rowspan="1" colspan="1">byte string (one-byte uint8_t for n, and then n bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x59</td>
            <td class="text-left" rowspan="1" colspan="1">byte string (two-byte uint16_t for n, and then n bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x5a</td>
            <td class="text-left" rowspan="1" colspan="1">byte string (four-byte uint32_t for n, and then n bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x5b</td>
            <td class="text-left" rowspan="1" colspan="1">byte string (eight-byte uint64_t for n, and then n bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x5f</td>
            <td class="text-left" rowspan="1" colspan="1">byte string, byte strings follow, terminated by "break"</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x60..0x77</td>
            <td class="text-left" rowspan="1" colspan="1">UTF-8 string (0x00..0x17 bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x78</td>
            <td class="text-left" rowspan="1" colspan="1">UTF-8 string (one-byte uint8_t for n, and then n bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x79</td>
            <td class="text-left" rowspan="1" colspan="1">UTF-8 string (two-byte uint16_t for n, and then n bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x7a</td>
            <td class="text-left" rowspan="1" colspan="1">UTF-8 string (four-byte uint32_t for n, and then n bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x7b</td>
            <td class="text-left" rowspan="1" colspan="1">UTF-8 string (eight-byte uint64_t for n, and then n bytes follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x7f</td>
            <td class="text-left" rowspan="1" colspan="1">UTF-8 string, UTF-8 strings follow, terminated by "break"</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x80..0x97</td>
            <td class="text-left" rowspan="1" colspan="1">array (0x00..0x17 data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x98</td>
            <td class="text-left" rowspan="1" colspan="1">array (one-byte uint8_t for n, and then n data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x99</td>
            <td class="text-left" rowspan="1" colspan="1">array (two-byte uint16_t for n, and then n data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x9a</td>
            <td class="text-left" rowspan="1" colspan="1">array (four-byte uint32_t for n, and then n data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x9b</td>
            <td class="text-left" rowspan="1" colspan="1">array (eight-byte uint64_t for n, and then n data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0x9f</td>
            <td class="text-left" rowspan="1" colspan="1">array, data items follow, terminated by "break"</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xa0..0xb7</td>
            <td class="text-left" rowspan="1" colspan="1">map (0x00..0x17 pairs of data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xb8</td>
            <td class="text-left" rowspan="1" colspan="1">map (one-byte uint8_t for n, and then n pairs of data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xb9</td>
            <td class="text-left" rowspan="1" colspan="1">map (two-byte uint16_t for n, and then n pairs of data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xba</td>
            <td class="text-left" rowspan="1" colspan="1">map (four-byte uint32_t for n, and then n pairs of data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xbb</td>
            <td class="text-left" rowspan="1" colspan="1">map (eight-byte uint64_t for n, and then n pairs of data items follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xbf</td>
            <td class="text-left" rowspan="1" colspan="1">map, pairs of data items follow, terminated by "break"</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xc0</td>
            <td class="text-left" rowspan="1" colspan="1">text-based date/time (data item follows; see <a href="#stringdatetimesect" class="xref">Section 3.4.1</a>)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xc1</td>
            <td class="text-left" rowspan="1" colspan="1">epoch-based date/time (data item follows; see <a href="#epochdatetimesect" class="xref">Section 3.4.2</a>)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xc2</td>
            <td class="text-left" rowspan="1" colspan="1">unsigned bignum (data item "byte string" follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xc3</td>
            <td class="text-left" rowspan="1" colspan="1">negative bignum (data item "byte string" follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xc4</td>
            <td class="text-left" rowspan="1" colspan="1">decimal Fraction (data item "array" follows; see <a href="#fractions" class="xref">Section 3.4.4</a>)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xc5</td>
            <td class="text-left" rowspan="1" colspan="1">bigfloat (data item "array" follows; see <a href="#fractions" class="xref">Section 3.4.4</a>)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xc6..0xd4</td>
            <td class="text-left" rowspan="1" colspan="1">(tag)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xd5..0xd7</td>
            <td class="text-left" rowspan="1" colspan="1">expected conversion (data item follows; see <a href="#convexpect" class="xref">Section 3.4.5.2</a>)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xd8..0xdb</td>
            <td class="text-left" rowspan="1" colspan="1">(more tags; 1/2/4/8 bytes of tag number and then a data item follow)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xe0..0xf3</td>
            <td class="text-left" rowspan="1" colspan="1">(simple value)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xf4</td>
            <td class="text-left" rowspan="1" colspan="1">false</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xf5</td>
            <td class="text-left" rowspan="1" colspan="1">true</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xf6</td>
            <td class="text-left" rowspan="1" colspan="1">null</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xf7</td>
            <td class="text-left" rowspan="1" colspan="1">undefined</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xf8</td>
            <td class="text-left" rowspan="1" colspan="1">(simple value, one byte follows)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xf9</td>
            <td class="text-left" rowspan="1" colspan="1">half-precision float (two-byte IEEE 754)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xfa</td>
            <td class="text-left" rowspan="1" colspan="1">single-precision float (four-byte IEEE 754)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xfb</td>
            <td class="text-left" rowspan="1" colspan="1">double-precision float (eight-byte IEEE 754)</td>
          </tr>
          <tr>
            <td class="text-left" rowspan="1" colspan="1">0xff</td>
            <td class="text-left" rowspan="1" colspan="1">"break" stop code</td>
          </tr>
        </tbody>
      </table>
</div>
</section>
</div>
<div id="pseudocode">
<section id="section-appendix.c">
      <h2 id="name-pseudocode">
<a href="#section-appendix.c" class="section-number selfRef">Appendix C. </a><a href="#name-pseudocode" class="section-name selfRef">Pseudocode</a>
      </h2>
<p id="section-appendix.c-1">The well-formedness of a CBOR item can be checked by the
pseudocode in <a href="#pseudo" class="xref">Figure 1</a>.  The data is well-formed if and only if:<a href="#section-appendix.c-1" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-appendix.c-2.1">the pseudocode does not "fail";<a href="#section-appendix.c-2.1" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-appendix.c-2.2">after execution of the pseudocode, no bytes are left in the input
(except in streaming applications).<a href="#section-appendix.c-2.2" class="pilcrow">¶</a>
</li>
      </ul>
<p id="section-appendix.c-3">The pseudocode has the following prerequisites:<a href="#section-appendix.c-3" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-appendix.c-4.1">take(n) reads n bytes from the input data and returns them as a byte
string.  If n bytes are no longer available, take(n) fails.<a href="#section-appendix.c-4.1" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-appendix.c-4.2">uint() converts a byte string into an unsigned integer by
interpreting the byte string in network byte order.<a href="#section-appendix.c-4.2" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-appendix.c-4.3">Arithmetic works as in C.<a href="#section-appendix.c-4.3" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-appendix.c-4.4">All variables are unsigned integers of sufficient range.<a href="#section-appendix.c-4.4" class="pilcrow">¶</a>
</li>
      </ul>
<p id="section-appendix.c-5">Note that <code>well_formed</code> returns the major type for well-formed
definite-length items, but 99 for an indefinite-length item (or -1 for
a "break" stop code, only if <code>breakable</code> is set).  This is used in
<code>well_formed_indefinite</code> to ascertain that indefinite-length strings
only contain definite-length strings as chunks.<a href="#section-appendix.c-5" class="pilcrow">¶</a></p>
<span id="name-pseudocode-for-well-formedn"></span><div id="pseudo">
<figure id="figure-1">
        <div id="section-appendix.c-6.1">
<pre class="sourcecode lang-pseudocode">
well_formed(breakable = false) {
  // process initial bytes
  ib = uint(take(1));
  mt = ib &gt;&gt; 5;
  val = ai = ib &amp; 0x1f;
  switch (ai) {
    case 24: val = uint(take(1)); break;
    case 25: val = uint(take(2)); break;
    case 26: val = uint(take(4)); break;
    case 27: val = uint(take(8)); break;
    case 28: case 29: case 30: fail();
    case 31:
      return well_formed_indefinite(mt, breakable);
  }
  // process content
  switch (mt) {
    // case 0, 1, 7 do not have content; just use val
    case 2: case 3: take(val); break; // bytes/UTF-8
    case 4: for (i = 0; i &lt; val; i++) well_formed(); break;
    case 5: for (i = 0; i &lt; val*2; i++) well_formed(); break;
    case 6: well_formed(); break;     // 1 embedded data item
    case 7: if (ai == 24 &amp;&amp; val &lt; 32) fail(); // bad simple
  }
  return mt;                    // definite-length data item
}

well_formed_indefinite(mt, breakable) {
  switch (mt) {
    case 2: case 3:
      while ((it = well_formed(true)) != -1)
        if (it != mt)           // need definite-length chunk
          fail();               //    of same type
      break;
    case 4: while (well_formed(true) != -1); break;
    case 5: while (well_formed(true) != -1) well_formed(); break;
    case 7:
      if (breakable)
        return -1;              // signal break out
      else fail();              // no enclosing indefinite
    default: fail();            // wrong mt
  }
  return 99;                    // indefinite-length data item
}
</pre>
</div>
<figcaption><a href="#figure-1" class="selfRef">Figure 1</a>:
<a href="#name-pseudocode-for-well-formedn" class="selfRef">Pseudocode for Well-Formedness Check</a>
        </figcaption></figure>
</div>
<p id="section-appendix.c-7">Note that the remaining complexity of a complete CBOR decoder is about
presenting data that has been decoded to the application in an
appropriate form.<a href="#section-appendix.c-7" class="pilcrow">¶</a></p>
<p id="section-appendix.c-8">Major types 0 and 1 are designed in such a way that they can be
encoded in C from a signed integer without actually doing an
if-then-else for positive/negative (<a href="#branchless" class="xref">Figure 2</a>).  This uses the
fact that (-1-n), the transformation for major type 1, is the same as
~n (bitwise complement) in C unsigned arithmetic; ~n can then be
expressed as (-1)^n for the negative case, while 0^n leaves n
unchanged for nonnegative.  The sign of a number can be converted to
-1 for negative and 0 for nonnegative (0 or positive) by
arithmetic-shifting the number by one bit less than the bit length of
the number (for example, by 63 for 64-bit numbers).<a href="#section-appendix.c-8" class="pilcrow">¶</a></p>
<span id="name-pseudocode-for-encoding-a-s"></span><div id="branchless">
<figure id="figure-2">
        <div id="section-appendix.c-9.1">
<pre class="sourcecode lang-pseudocode">
void encode_sint(int64_t n) {
  uint64t ui = n &gt;&gt; 63;    // extend sign to whole length
  unsigned mt = ui &amp; 0x20; // extract (shifted) major type
  ui ^= n;                 // complement negatives
  if (ui &lt; 24)
    *p++ = mt + ui;
  else if (ui &lt; 256) {
    *p++ = mt + 24;
    *p++ = ui;
  } else
       ...
</pre>
</div>
<figcaption><a href="#figure-2" class="selfRef">Figure 2</a>:
<a href="#name-pseudocode-for-encoding-a-s" class="selfRef">Pseudocode for Encoding a Signed Integer</a>
        </figcaption></figure>
</div>
<p id="section-appendix.c-10">See <a href="#terminology" class="xref">Section 1.2</a> for some specific assumptions about the profile of
the C language used in these pieces of code.<a href="#section-appendix.c-10" class="pilcrow">¶</a></p>
</section>
</div>
<div id="half-precision">
<section id="section-appendix.d">
      <h2 id="name-half-precision">
<a href="#section-appendix.d" class="section-number selfRef">Appendix D. </a><a href="#name-half-precision" class="section-name selfRef">Half-Precision</a>
      </h2>
<p id="section-appendix.d-1">As half-precision floating-point numbers were only added to IEEE 754
in 2008 <span>[<a href="#IEEE754" class="xref">IEEE754</a>]</span>, today's programming platforms often still only have limited
support for them.  It is very easy to include at least decoding
support for them even without such support.  An example of a small
decoder for half-precision floating-point numbers in the C language is
shown in <a href="#decode-half-c" class="xref">Figure 3</a>.  A similar program for Python is in
<a href="#decode-half-py" class="xref">Figure 4</a>; this code assumes that the 2-byte value has
already been decoded as an (unsigned short) integer in network byte
order (as would be done by the pseudocode in <a href="#pseudocode" class="xref">Appendix C</a>).<a href="#section-appendix.d-1" class="pilcrow">¶</a></p>
<span id="name-c-code-for-a-half-precision"></span><div id="decode-half-c">
<figure id="figure-3">
        <div id="section-appendix.d-2.1">
<pre class="sourcecode lang-c">
#include &lt;math.h&gt;

double decode_half(unsigned char *halfp) {
  unsigned half = (halfp[0] &lt;&lt; 8) + halfp[1];
  unsigned exp = (half &gt;&gt; 10) &amp; 0x1f;
  unsigned mant = half &amp; 0x3ff;
  double val;
  if (exp == 0) val = ldexp(mant, -24);
  else if (exp != 31) val = ldexp(mant + 1024, exp - 25);
  else val = mant == 0 ? INFINITY : NAN;
  return half &amp; 0x8000 ? -val : val;
}
</pre>
</div>
<figcaption><a href="#figure-3" class="selfRef">Figure 3</a>:
<a href="#name-c-code-for-a-half-precision" class="selfRef">C Code for a Half-Precision Decoder</a>
        </figcaption></figure>
</div>
<span id="name-python-code-for-a-half-prec"></span><div id="decode-half-py">
<figure id="figure-4">
        <div id="section-appendix.d-3.1">
<pre class="sourcecode lang-python">
import struct
from math import ldexp

def decode_single(single):
    return struct.unpack("!f", struct.pack("!I", single))[0]

def decode_half(half):
    valu = (half &amp; 0x7fff) &lt;&lt; 13 | (half &amp; 0x8000) &lt;&lt; 16
    if ((half &amp; 0x7c00) != 0x7c00):
        return ldexp(decode_single(valu), 112)
    return decode_single(valu | 0x7f800000)
</pre>
</div>
<figcaption><a href="#figure-4" class="selfRef">Figure 4</a>:
<a href="#name-python-code-for-a-half-prec" class="selfRef">Python Code for a Half-Precision Decoder</a>
        </figcaption></figure>
</div>
</section>
</div>
<div id="comparison-app">
<section id="section-appendix.e">
      <h2 id="name-comparison-of-other-binary-">
<a href="#section-appendix.e" class="section-number selfRef">Appendix E. </a><a href="#name-comparison-of-other-binary-" class="section-name selfRef">Comparison of Other Binary Formats to CBOR's Design Objectives</a>
      </h2>
<p id="section-appendix.e-1">The proposal for CBOR follows a history of binary formats that is as
long as the history of computers themselves. Different formats have
had different objectives. In most cases, the objectives of the format
were never stated, although they can sometimes be implied by the
context where the format was first used. Some formats were meant to be
universally usable, although history has proven that no binary format
meets the needs of all protocols and applications.<a href="#section-appendix.e-1" class="pilcrow">¶</a></p>
<p id="section-appendix.e-2">CBOR differs from many of these formats due to it starting with a set
of objectives and attempting to meet just those. This section compares
a few of the dozens of formats with CBOR's objectives in order to help
the reader decide if they want to use CBOR or a different format for a
particular protocol or application.<a href="#section-appendix.e-2" class="pilcrow">¶</a></p>
<p id="section-appendix.e-3">Note that the discussion here is not meant to be a criticism of any
format: to the best of our knowledge, no format before CBOR was meant
to cover CBOR's objectives in the priority we have assigned them.  A
brief recap of the objectives from <a href="#objectives" class="xref">Section 1.1</a> is:<a href="#section-appendix.e-3" class="pilcrow">¶</a></p>
<ol start="1" type="1" class="normal type-1" id="section-appendix.e-4">
<li id="section-appendix.e-4.1">unambiguous encoding of most common data formats from Internet
  standards<a href="#section-appendix.e-4.1" class="pilcrow">¶</a>
</li>
        <li id="section-appendix.e-4.2">code compactness for encoder or decoder<a href="#section-appendix.e-4.2" class="pilcrow">¶</a>
</li>
        <li id="section-appendix.e-4.3">no schema description needed<a href="#section-appendix.e-4.3" class="pilcrow">¶</a>
</li>
        <li id="section-appendix.e-4.4">reasonably compact serialization<a href="#section-appendix.e-4.4" class="pilcrow">¶</a>
</li>
        <li id="section-appendix.e-4.5">applicability to constrained and unconstrained applications<a href="#section-appendix.e-4.5" class="pilcrow">¶</a>
</li>
        <li id="section-appendix.e-4.6">good JSON conversion<a href="#section-appendix.e-4.6" class="pilcrow">¶</a>
</li>
        <li id="section-appendix.e-4.7">extensibility<a href="#section-appendix.e-4.7" class="pilcrow">¶</a>
</li>
      </ol>
<p id="section-appendix.e-5">A discussion of CBOR and other formats with respect to a different set
of design objectives is provided in Section <a href="https://www.rfc-editor.org/rfc/rfc8618#section-5" class="relref">5</a> 
and Appendix <a href="https://www.rfc-editor.org/rfc/rfc8618#appendix-C" class="relref">C</a> of
<span>[<a href="#RFC8618" class="xref">RFC8618</a>]</span>.<a href="#section-appendix.e-5" class="pilcrow">¶</a></p>
<div id="asn1-der-ber-and-per">
<section id="section-e.1">
        <h2 id="name-asn1-der-ber-and-per">
<a href="#section-e.1" class="section-number selfRef">E.1. </a><a href="#name-asn1-der-ber-and-per" class="section-name selfRef">ASN.1 DER, BER, and PER</a>
        </h2>
<p id="section-e.1-1"><span>[<a href="#ASN.1" class="xref">ASN.1</a>]</span> has many serializations. In the IETF, DER and BER are the
most common. The serialized output is not particularly compact for
many items, and the code needed to decode numeric items can be complex
on a constrained device.<a href="#section-e.1-1" class="pilcrow">¶</a></p>
<p id="section-e.1-2">Few (if any) IETF protocols have adopted one of the several variants
of Packed Encoding Rules (PER).  There could be many reasons for this,
but one that is commonly stated is that PER makes use of the schema
even for parsing the surface structure of the data item, requiring
significant tool support.  There are different versions of the ASN.1
schema language in use, which has also hampered adoption.<a href="#section-e.1-2" class="pilcrow">¶</a></p>
</section>
</div>
<div id="messagepack">
<section id="section-e.2">
        <h2 id="name-messagepack">
<a href="#section-e.2" class="section-number selfRef">E.2. </a><a href="#name-messagepack" class="section-name selfRef">MessagePack</a>
        </h2>
<p id="section-e.2-1"><span>[<a href="#MessagePack" class="xref">MessagePack</a>]</span> is a concise, widely implemented counted binary
serialization format, similar in many properties to CBOR, although
somewhat less regular.  While the data model can be used to represent
JSON data, MessagePack has also been used in many remote procedure
call (RPC) applications and for long-term storage of data.<a href="#section-e.2-1" class="pilcrow">¶</a></p>
<p id="section-e.2-2">MessagePack has been essentially stable since it was first published
around 2011; it has not yet had a transition.  The evolution of
MessagePack is impeded by an imperative to maintain complete backwards
compatibility with existing stored data, while only few bytecodes are
still available for extension.  Repeated requests over the years from
the MessagePack user community to separate out binary and text strings
in the encoding recently have led to an extension proposal that would
leave MessagePack's "raw" data ambiguous between its usages for binary
and text data. The extension mechanism for MessagePack remains
unclear.<a href="#section-e.2-2" class="pilcrow">¶</a></p>
</section>
</div>
<div id="bson">
<section id="section-e.3">
        <h2 id="name-bson">
<a href="#section-e.3" class="section-number selfRef">E.3. </a><a href="#name-bson" class="section-name selfRef">BSON</a>
        </h2>
<p id="section-e.3-1"><span>[<a href="#BSON" class="xref">BSON</a>]</span> is a data format that was developed for the storage of
JSON-like maps (JSON objects) in the MongoDB database.  Its major
distinguishing feature is the capability for in-place update,
which prevents a compact representation.  BSON uses a counted
representation except for map keys, which are null-byte terminated.
While BSON can be used for the representation of JSON-like objects on
the wire, its specification is dominated by the requirements of the
database application and has become somewhat baroque. The status of
how BSON extensions will be implemented remains unclear.<a href="#section-e.3-1" class="pilcrow">¶</a></p>
</section>
</div>
<div id="msdtp-rfc-713">
<section id="section-e.4">
        <h2 id="name-msdtp-rfc-713">
<a href="#section-e.4" class="section-number selfRef">E.4. </a><a href="#name-msdtp-rfc-713" class="section-name selfRef">MSDTP: RFC 713</a>
        </h2>
<p id="section-e.4-1">Message Services Data Transmission (MSDTP) is a very early example of
a compact message format; it is described in <span>[<a href="#RFC0713" class="xref">RFC0713</a>]</span>, written
in 1976. It is included here for its historical value, not because it
was ever widely used.<a href="#section-e.4-1" class="pilcrow">¶</a></p>
</section>
</div>
<div id="conciseness-on-the-wire">
<section id="section-e.5">
        <h2 id="name-conciseness-on-the-wire">
<a href="#section-e.5" class="section-number selfRef">E.5. </a><a href="#name-conciseness-on-the-wire" class="section-name selfRef">Conciseness on the Wire</a>
        </h2>
<p id="section-e.5-1">While CBOR's design objective of code compactness for encoders and
decoders is a higher priority than its objective of conciseness on the
wire, many people focus on the wire size. <a href="#concise" class="xref">Table 8</a> shows some
encoding examples for the simple nested array [1, [2, 3]]; where some
form of indefinite-length encoding is supported by the encoding,
[_ 1, [2, 3]] (indefinite length on the outer array) is also
shown.<a href="#section-e.5-1" class="pilcrow">¶</a></p>
<span id="name-examples-for-different-leve"></span><div id="concise">
<table class="center" id="table-8">
          <caption>
<a href="#table-8" class="selfRef">Table 8</a>:
<a href="#name-examples-for-different-leve" class="selfRef">Examples for Different Levels of Conciseness</a>
          </caption>
<thead>
            <tr>
              <th class="text-left" rowspan="1" colspan="1">Format</th>
              <th class="text-left" rowspan="1" colspan="1">[1, [2, 3]]</th>
              <th class="text-left" rowspan="1" colspan="1">[_ 1, [2, 3]]</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">RFC 713</td>
              <td class="text-left" rowspan="1" colspan="1">c2 05 81 c2 02 82 83</td>
              <td class="text-left" rowspan="1" colspan="1"> </td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">ASN.1 BER</td>
              <td class="text-left" rowspan="1" colspan="1">30 0b 02 01 01 30 06 02 01 02 02 01 03</td>
              <td class="text-left" rowspan="1" colspan="1">30 80 02 01 01 30 06 02 01 02 02 01 03 00 00</td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">MessagePack</td>
              <td class="text-left" rowspan="1" colspan="1">92 01 92 02 03</td>
              <td class="text-left" rowspan="1" colspan="1"> </td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">BSON</td>
              <td class="text-left" rowspan="1" colspan="1">22 00 00 00 10 30 00 01 00 00 00 04 31 00 13 00 00 00 10 30 00 02 00 00 00 10 31 00 03 00 00 00 00 00</td>
              <td class="text-left" rowspan="1" colspan="1"> </td>
            </tr>
            <tr>
              <td class="text-left" rowspan="1" colspan="1">CBOR</td>
              <td class="text-left" rowspan="1" colspan="1">82 01 82 02 03</td>
              <td class="text-left" rowspan="1" colspan="1">9f 01 82 02 03 ff</td>
            </tr>
          </tbody>
        </table>
</div>
</section>
</div>
</section>
</div>
<div id="errors">
<section id="section-appendix.f">
      <h2 id="name-well-formedness-errors-and-">
<a href="#section-appendix.f" class="section-number selfRef">Appendix F. </a><a href="#name-well-formedness-errors-and-" class="section-name selfRef">Well-Formedness Errors and Examples</a>
      </h2>
<p id="section-appendix.f-1">There are three basic kinds of well-formedness errors that can occur
in decoding a CBOR data item:<a href="#section-appendix.f-1" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-appendix.f-2">
        <dt id="section-appendix.f-2.1">Too much data:</dt>
        <dd style="margin-left: 1.5em" id="section-appendix.f-2.2">There are input bytes left that were not consumed.
This is only an error if the application assumed that the input
bytes would span exactly one data item.  Where the application
uses the self-delimiting nature of CBOR encoding to permit
additional data after the data item, as is done in CBOR
sequences <span>[<a href="#RFC8742" class="xref">RFC8742</a>]</span>, for example, the CBOR decoder can simply
indicate which part of the input has not been consumed.<a href="#section-appendix.f-2.2" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
<dt id="section-appendix.f-2.3">Too little data:</dt>
        <dd style="margin-left: 1.5em" id="section-appendix.f-2.4">The input data available would need additional
bytes added at their end for a complete CBOR data item.  This may
indicate the input is truncated; it is also a common error when
trying to decode random data as CBOR.  For some
applications, however, this may not actually be an error, as the
application may not be certain it has all the data yet and can
obtain or wait for additional input bytes.  Some of
these applications may have an upper limit for how much additional
data can appear; here the decoder may be able to indicate that the
encoded CBOR data item cannot be completed within this limit.<a href="#section-appendix.f-2.4" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
<dt id="section-appendix.f-2.5">Syntax error:</dt>
        <dd style="margin-left: 1.5em" id="section-appendix.f-2.6">The input data are not consistent with the
requirements of the CBOR encoding, and this cannot be remedied by
adding (or removing) data at the end.<a href="#section-appendix.f-2.6" class="pilcrow">¶</a>
</dd>
      <dd class="break"></dd>
</dl>
<p id="section-appendix.f-3">In <a href="#pseudocode" class="xref">Appendix C</a>, errors of the first kind are addressed in the first
paragraph and bullet list (requiring "no bytes are left"), and errors of
the second kind are addressed in the second paragraph/bullet list
(failing "if n bytes are no longer available").  Errors of the third
kind are identified in the pseudocode by specific instances of calling
fail(), in order:<a href="#section-appendix.f-3" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-appendix.f-4.1">a reserved value is used for additional information (28, 29, 30)<a href="#section-appendix.f-4.1" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-appendix.f-4.2">major type 7, additional information 24, value &lt; 32 (incorrect)<a href="#section-appendix.f-4.2" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-appendix.f-4.3">incorrect substructure of indefinite-length byte string or text string (may
only contain definite-length strings of the same major type)<a href="#section-appendix.f-4.3" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-appendix.f-4.4">"break" stop code (major type 7, additional information 31) occurs in a value position of a map or
except at a position directly in an indefinite-length item where
also another enclosed data item could occur<a href="#section-appendix.f-4.4" class="pilcrow">¶</a>
</li>
        <li class="normal" id="section-appendix.f-4.5">additional information 31 used with major type 0, 1, or 6<a href="#section-appendix.f-4.5" class="pilcrow">¶</a>
</li>
      </ul>
<div id="examples-for-cbor-data-items-that-are-not-well-formed">
<section id="section-f.1">
        <h2 id="name-examples-of-cbor-data-items">
<a href="#section-f.1" class="section-number selfRef">F.1. </a><a href="#name-examples-of-cbor-data-items" class="section-name selfRef">Examples of CBOR Data Items That Are Not Well-Formed</a>
        </h2>
<p id="section-f.1-1">This subsection shows a few examples for CBOR data items that are not
well-formed.  Each example is a sequence of bytes, each shown in
hexadecimal; multiple examples in a list are separated by commas.<a href="#section-f.1-1" class="pilcrow">¶</a></p>
<p id="section-f.1-2">Examples for well-formedness error kind 1 (too much data) can easily
be formed by adding data to a well-formed encoded CBOR data item.<a href="#section-f.1-2" class="pilcrow">¶</a></p>
<p id="section-f.1-3">Similarly, examples for well-formedness error kind 2 (too little data)
can be formed by truncating a well-formed encoded CBOR data item.  In
test suites, it may be beneficial to specifically test with incomplete
data items that would require large amounts of addition to be
completed (for instance by starting the encoding of a string of a very
large size).<a href="#section-f.1-3" class="pilcrow">¶</a></p>
<p id="section-f.1-4">A premature end of the input can occur in a head or within the enclosed
data, which may be bare strings or enclosed data items that are either
counted or should have been ended by a "break" stop code.<a href="#section-f.1-4" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlParallel" id="section-f.1-5">
          <dt id="section-f.1-5.1">End of input in a head:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-5.2">18, 19, 1a, 1b, 19 01, 1a 01 02, 1b 01 02 03
04 05 06 07, 38, 58, 78, 98, 9a 01 ff 00, b8, d8, f8, f9 00, fa 00
00, fb 00 00 00<a href="#section-f.1-5.2" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-f.1-5.3">Definite-length strings with short data:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-5.4">41, 61, 5a ff ff ff ff 00,
5b ff ff ff ff ff ff ff ff 01 02 03, 7a ff ff ff ff 00, 7b 7f ff ff
ff ff ff ff ff 01 02 03<a href="#section-f.1-5.4" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-f.1-5.5">Definite-length maps and arrays not closed with enough items:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-5.6">81, 81
81 81 81 81 81 81 81 81, 82 00, a1, a2 01 02, a1 00, a2 00 00 00<a href="#section-f.1-5.6" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-f.1-5.7">Tag number not followed by tag content:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-5.8">c0<a href="#section-f.1-5.8" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-f.1-5.9">Indefinite-length strings not closed by a "break" stop code:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-5.10">5f 41 00, 7f 61 00<a href="#section-f.1-5.10" class="pilcrow">¶</a>
</dd>
          <dd class="break"></dd>
<dt id="section-f.1-5.11">Indefinite-length maps and arrays not closed by a "break" stop code:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-5.12">
9f, 9f 01 02, bf, bf 01 02 01 02, 81 9f, 9f 80 00, 9f 9f 9f 9f 9f ff
ff ff ff, 9f 81 9f 81 9f 9f ff ff ff<a href="#section-f.1-5.12" class="pilcrow">¶</a>
</dd>
        <dd class="break"></dd>
</dl>
<p id="section-f.1-6">A few examples for the five subkinds of well-formedness error kind 3
(syntax error) are shown below.<a href="#section-f.1-6" class="pilcrow">¶</a></p>
<span class="break"></span><dl class="dlNewline" id="section-f.1-7">
          <dt id="section-f.1-7.1">Subkind 1:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-7.2">
            <p id="section-f.1-7.2.1"></p>
<span class="break"></span><dl class="dlParallel" id="section-f.1-7.2.2">
              <dt id="section-f.1-7.2.2.1">Reserved additional information values:</dt>
              <dd style="margin-left: 1.5em" id="section-f.1-7.2.2.2">1c, 1d, 1e, 3c, 3d, 3e, 5c,
5d, 5e, 7c, 7d, 7e, 9c, 9d, 9e, bc, bd, be, dc, dd, de, fc, fd, fe,<a href="#section-f.1-7.2.2.2" class="pilcrow">¶</a>
</dd>
            <dd class="break"></dd>
</dl>
</dd>
          <dd class="break"></dd>
<dt id="section-f.1-7.3">Subkind 2:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-7.4">
            <p id="section-f.1-7.4.1"></p>
<span class="break"></span><dl class="dlParallel" id="section-f.1-7.4.2">
              <dt id="section-f.1-7.4.2.1">Reserved two-byte encodings of simple values:</dt>
              <dd style="margin-left: 1.5em" id="section-f.1-7.4.2.2">f8 00, f8 01, f8 18, f8 1f<a href="#section-f.1-7.4.2.2" class="pilcrow">¶</a>
</dd>
            <dd class="break"></dd>
</dl>
</dd>
          <dd class="break"></dd>
<dt id="section-f.1-7.5">Subkind 3:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-7.6">
            <p id="section-f.1-7.6.1"></p>
<span class="break"></span><dl class="dlParallel" id="section-f.1-7.6.2">
              <dt id="section-f.1-7.6.2.1">Indefinite-length string chunks not of the correct type:</dt>
              <dd style="margin-left: 1.5em" id="section-f.1-7.6.2.2">5f 00 ff,
5f 21 ff, 5f 61 00 ff, 5f 80 ff, 5f a0 ff, 5f c0 00 ff, 5f e0 ff, 7f
41 00 ff<a href="#section-f.1-7.6.2.2" class="pilcrow">¶</a>
</dd>
              <dd class="break"></dd>
<dt id="section-f.1-7.6.2.3">Indefinite-length string chunks not definite length:</dt>
              <dd style="margin-left: 1.5em" id="section-f.1-7.6.2.4">
5f 5f 41 00 ff ff, 7f 7f 61 00 ff ff<a href="#section-f.1-7.6.2.4" class="pilcrow">¶</a>
</dd>
            <dd class="break"></dd>
</dl>
</dd>
          <dd class="break"></dd>
<dt id="section-f.1-7.7">Subkind 4:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-7.8">
            <p id="section-f.1-7.8.1"></p>
<span class="break"></span><dl class="dlParallel" id="section-f.1-7.8.2">
              <dt id="section-f.1-7.8.2.1">Break occurring on its own outside of an indefinite-length item:</dt>
              <dd style="margin-left: 1.5em" id="section-f.1-7.8.2.2"> ff<a href="#section-f.1-7.8.2.2" class="pilcrow">¶</a>
</dd>
              <dd class="break"></dd>
<dt id="section-f.1-7.8.2.3">Break occurring in a definite-length array or map or a tag:</dt>
              <dd style="margin-left: 1.5em" id="section-f.1-7.8.2.4">81 ff,
82 00 ff, a1 ff, a1 ff 00, a1 00 ff, a2 00 00 ff, 9f 81 ff, 9f 82 9f
81 9f 9f ff ff ff ff<a href="#section-f.1-7.8.2.4" class="pilcrow">¶</a>
</dd>
              <dd class="break"></dd>
<dt id="section-f.1-7.8.2.5">Break in an indefinite-length map that would lead to an odd number of items
(break in a value position):</dt>
              <dd style="margin-left: 1.5em" id="section-f.1-7.8.2.6">bf 00 ff, bf 00 00 00 ff<a href="#section-f.1-7.8.2.6" class="pilcrow">¶</a>
</dd>
            <dd class="break"></dd>
</dl>
</dd>
          <dd class="break"></dd>
<dt id="section-f.1-7.9">Subkind 5:</dt>
          <dd style="margin-left: 1.5em" id="section-f.1-7.10">
            <p id="section-f.1-7.10.1"></p>
<span class="break"></span><dl class="dlParallel" id="section-f.1-7.10.2">
              <dt id="section-f.1-7.10.2.1">Major type 0, 1, 6 with additional information 31:</dt>
              <dd style="margin-left: 1.5em" id="section-f.1-7.10.2.2">1f, 3f, df<a href="#section-f.1-7.10.2.2" class="pilcrow">¶</a>
</dd>
            <dd class="break"></dd>
</dl>
</dd>
        <dd class="break"></dd>
</dl>
</section>
</div>
</section>
</div>
<div id="changes-from-rfc-7049">
<section id="section-appendix.g">
      <h2 id="name-changes-from-rfc-7049">
<a href="#section-appendix.g" class="section-number selfRef">Appendix G. </a><a href="#name-changes-from-rfc-7049" class="section-name selfRef">Changes from RFC 7049</a>
      </h2>
<p id="section-appendix.g-1">As discussed in the introduction,
this document formally obsoletes RFC 7049 while keeping full compatibility
with the interchange format from RFC 7049. This document provides editorial
improvements, added detail, and fixed errata.
This document does not create a new version of the format.<a href="#section-appendix.g-1" class="pilcrow">¶</a></p>
<div id="errata-processing-clerical-changes">
<section id="section-g.1">
        <h2 id="name-errata-processing-and-cleri">
<a href="#section-g.1" class="section-number selfRef">G.1. </a><a href="#name-errata-processing-and-cleri" class="section-name selfRef">Errata Processing and Clerical Changes</a>
        </h2>
<p id="section-g.1-1">The two verified errata on RFC 7049, 
<span>[<a href="#Err3764" class="xref">Err3764</a>]</span> 
and <span>[<a href="#Err3770" class="xref">Err3770</a>]</span>, concerned
two encoding examples in the text that have been corrected
(<a href="#bignums" class="xref">Section 3.4.3</a>: "29" -&gt; "49", 
<a href="#numbers" class="xref">Section 5.5</a>: "0b000_11101" -&gt;
"0b000_11001").  Also, RFC 7049 contained an example using the numeric
value 24 for a simple value <span>[<a href="#Err5917" class="xref">Err5917</a>]</span>, 
which is not well-formed; this example has
been removed.  Errata report 5763 <span>[<a href="#Err5763" class="xref">Err5763</a>]</span> 
pointed to an error in the
wording of the definition of tags; this was resolved during a rewrite
of <a href="#tags" class="xref">Section 3.4</a>.  Errata report 5434 
<span>[<a href="#Err5434" class="xref">Err5434</a>]</span> pointed out that the Universal Binary JSON
(UBJSON) example
in <a href="#comparison-app" class="xref">Appendix E</a> no longer complied with the version of UBJSON
current at the time of the errata report submission.  It turned out that the
UBJSON specification had completely changed since 2013; this example
therefore was removed.  Other errata reports 
<span>[<a href="#Err4409" class="xref">Err4409</a>]</span>
          <span>[<a href="#Err4963" class="xref">Err4963</a>]</span>
          <span>[<a href="#Err4964" class="xref">Err4964</a>]</span> 
complained that the map key sorting rules for canonical encoding were
onerous; these led to a reconsideration of the canonical encoding
suggestions and replacement by the deterministic encoding suggestions
(described below).  An editorial suggestion in errata report 4294 
<span>[<a href="#Err4294" class="xref">Err4294</a>]</span> was also
implemented (improved symmetry by adding "Second value" to a comment
to the last example in <a href="#indef" class="xref">Section 3.2.2</a>).<a href="#section-g.1-1" class="pilcrow">¶</a></p>
<p id="section-g.1-2">Other clerical changes include:<a href="#section-g.1-2" class="pilcrow">¶</a></p>
<ul class="normal">
<li class="normal" id="section-g.1-3.1">the use of new xml2rfc functionality <span>[<a href="#RFC7991" class="xref">RFC7991</a>]</span>;<a href="#section-g.1-3.1" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-g.1-3.2">more explanation of the notation used;<a href="#section-g.1-3.2" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-g.1-3.3">the update of references, e.g., from RFC 4627 to 
<span>[<a href="#RFC8259" class="xref">RFC8259</a>]</span>,
from CNN-TERMS to <span>[<a href="#RFC7228" class="xref">RFC7228</a>]</span>, and
from the 5.1 edition to the 11th edition of <span>[<a href="#ECMA262" class="xref">ECMA262</a>]</span>; 
the addition of a reference to <span>[<a href="#IEEE754" class="xref">IEEE754</a>]</span> and importation of required definitions; 
the addition of references to <span>[<a href="#C" class="xref">C</a>]</span> and <span>[<a href="#Cplusplus20" class="xref">Cplusplus20</a>]</span>;
and the addition of a reference to <span>[<a href="#RFC8618" class="xref">RFC8618</a>]</span> that further illustrates the discussion in
<a href="#comparison-app" class="xref">Appendix E</a>;<a href="#section-g.1-3.3" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-g.1-3.4">in the discussion of diagnostic notation (<a href="#diagnostic-notation" class="xref">Section 8</a>), 
the "Extended Diagnostic Notation" (EDN) defined in <span>[<a href="#RFC8610" class="xref">RFC8610</a>]</span> is now mentioned, 
the gap in representing NaN payloads is now highlighted,  
and an explanation of representing indefinite-length strings with 
no chunks has been added (<a href="#encoding-indicators" class="xref">Section 8.1</a>);<a href="#section-g.1-3.4" class="pilcrow">¶</a>
</li>
          <li class="normal" id="section-g.1-3.5">the addition of this appendix.<a href="#section-g.1-3.5" class="pilcrow">¶</a>
</li>
        </ul>
</section>
</div>
<div id="changes-in-iana-considerations">
<section id="section-g.2">
        <h2 id="name-changes-in-iana-considerati">
<a href="#section-g.2" class="section-number selfRef">G.2. </a><a href="#name-changes-in-iana-considerati" class="section-name selfRef">Changes in IANA Considerations</a>
        </h2>
<p id="section-g.2-1">The IANA considerations were generally updated (clerical changes,
e.g., now pointing to the CBOR Working Group as the author of the
specification).  References to the respective IANA registries were
added to the informative references.<a href="#section-g.2-1" class="pilcrow">¶</a></p>
<p id="section-g.2-2">In the "Concise Binary Object Representation (CBOR) Tags" registry
 <span>[<a href="#IANA.cbor-tags" class="xref">IANA.cbor-tags</a>]</span>,
 tags in the space from 256 to 32767 (lower half of
"1+2") are no longer assigned by First Come First Served; this range
is now Specification Required.<a href="#section-g.2-2" class="pilcrow">¶</a></p>
</section>
</div>
<div id="changes-in-suggestions-and-other-informational-components">
<section id="section-g.3">
        <h2 id="name-changes-in-suggestions-and-">
<a href="#section-g.3" class="section-number selfRef">G.3. </a><a href="#name-changes-in-suggestions-and-" class="section-name selfRef">Changes in Suggestions and Other Informational Components</a>
        </h2>
<p id="section-g.3-1">While revising the document, beyond the addressing of the errata reports, 
   the working group drew upon nearly seven years of experience with CBOR 
   in a diverse set of applications. This led to a number of editorial
   changes, including adding tables for illustration, but also
   emphasizing some aspects and de-emphasizing others.<a href="#section-g.3-1" class="pilcrow">¶</a></p>
<p id="section-g.3-2">A significant addition is <a href="#cbor-data-models" class="xref">Section 2</a>, which
discusses the CBOR data model and its small variations involved in the
processing of CBOR.  The introduction of terms for those variations (basic generic,
extended generic, specific) enables more concise language in other
places of the document and also helps to clarify expectations of
implementations and of the extensibility features of the format.<a href="#section-g.3-2" class="pilcrow">¶</a></p>
<p id="section-g.3-3">As a format derived from the JSON ecosystem, RFC 7049 was influenced
by the JSON number system that was in turn inherited from JavaScript
at the time.  JSON does not provide distinct integers and floating-point
values (and the latter are decimal in the format).  CBOR
provides binary representations of numbers, which do differ between
integers and floating-point values.  Experience from implementation and use
suggested that the separation between these two number
domains should be more clearly drawn in the document; language that
suggested an integer could seamlessly stand in for a floating-point
value was removed.  Also, a suggestion (based on I-JSON <span>[<a href="#RFC7493" class="xref">RFC7493</a>]</span>)
was added for handling these types when converting JSON to CBOR, and
the use of a specific rounding mechanism has been recommended.<a href="#section-g.3-3" class="pilcrow">¶</a></p>
<p id="section-g.3-4">For a single value in the data model, CBOR often provides multiple
encoding options.  A new section (<a href="#serialization-considerations" class="xref">Section 4</a>) introduces the term
"preferred serialization" (<a href="#preferred" class="xref">Section 4.1</a>) and defines it for various
kinds of data items.  On the basis of this terminology, the section
then discusses how a CBOR-based protocol can define "deterministic
encoding" (<a href="#det-enc" class="xref">Section 4.2</a>), which avoids terms
"canonical" and "canonicalization" from RFC 7049.  The suggestion of "Core
Deterministic Encoding Requirements" (<a href="#core-det" class="xref">Section 4.2.1</a>) enables generic
support for such protocol-defined encoding requirements.  This document
further eases the implementation of deterministic encoding by
simplifying the map ordering suggested in RFC 7049 to a simple
lexicographic ordering of encoded keys.  A description of the older
suggestion is kept as an alternative, now termed "length-first map key
ordering" (<a href="#length-first" class="xref">Section 4.2.3</a>).<a href="#section-g.3-4" class="pilcrow">¶</a></p>
<p id="section-g.3-5">The terminology for well-formed and valid data was sharpened and more
stringently used, avoiding less well-defined alternative terms such as
"syntax error", "decoding error", and "strict mode" outside of examples.
Also, a third level of requirements that an
application has on its input data beyond CBOR-level validity is now explicitly called out.
Well-formed (processable at all), valid (checked by a
validity-checking generic decoder), and expected input (as checked by
the application) are treated as a hierarchy of layers of
acceptability.<a href="#section-g.3-5" class="pilcrow">¶</a></p>
<p id="section-g.3-6">The handling of non-well-formed simple values was clarified in text
and pseudocode.  <a href="#errors" class="xref">Appendix F</a> was added to discuss well-formedness
errors and provide examples for them.  The pseudocode was updated to
be more portable, and some portability considerations were added.<a href="#section-g.3-6" class="pilcrow">¶</a></p>
<p id="section-g.3-7">The discussion of validity has been sharpened in two areas.  Map
validity (handling of duplicate keys) was clarified, and the domain of
applicability of certain implementation choices explained.  Also,
while streamlining the terminology for tags, tag numbers, and tag
content, discussion was added on tag validity, and the restrictions
were clarified on tag content, in general and specifically for tag 1.<a href="#section-g.3-7" class="pilcrow">¶</a></p>
<p id="section-g.3-8">An implementation note (and note for future tag definitions) was added
to <a href="#tags" class="xref">Section 3.4</a> about defining tags with semantics that depend on
serialization order.<a href="#section-g.3-8" class="pilcrow">¶</a></p>
<p id="section-g.3-9">Tag 35 is not defined by this document; the registration
based on the definition in RFC 7049 remains in place.<a href="#section-g.3-9" class="pilcrow">¶</a></p>
<p id="section-g.3-10">Terminology was introduced in <a href="#encoding" class="xref">Section 3</a> for "argument" and "head",
simplifying further discussion.<a href="#section-g.3-10" class="pilcrow">¶</a></p>
<p id="section-g.3-11">The security considerations (<a href="#securitycons" class="xref">Section 10</a>) 
were mostly rewritten and significantly
expanded; in multiple other places, the document is now more explicit
that a decoder cannot simply condone well-formedness errors.<a href="#section-g.3-11" class="pilcrow">¶</a></p>
</section>
</div>
</section>
</div>
<div id="acknowledgements">
<section id="section-appendix.h">
      <h2 id="name-acknowledgements">
<a href="#name-acknowledgements" class="section-name selfRef">Acknowledgements</a>
      </h2>
<p id="section-appendix.h-1">CBOR was inspired by MessagePack.  MessagePack was developed and
promoted by <span class="contact-name">Sadayuki Furuhashi</span> ("frsyuki").  This reference to
MessagePack is solely for attribution; CBOR is not intended as a
version of, or replacement for, MessagePack, as it has different design
goals and requirements.<a href="#section-appendix.h-1" class="pilcrow">¶</a></p>
<p id="section-appendix.h-2">The need for functionality beyond the original MessagePack
specification became obvious to many people at about the same time
around the year 2012.  BinaryPack is a minor derivation of MessagePack
that was developed by <span class="contact-name">Eric Zhang</span> for the binaryjs project.  A similar,
but different, extension was made by <span class="contact-name">Tim Caswell</span> for his msgpack-js
and msgpack-js-browser projects.  Many people have contributed to the
discussion about extending MessagePack to separate text string
representation from byte string representation.<a href="#section-appendix.h-2" class="pilcrow">¶</a></p>
<p id="section-appendix.h-3">The encoding of the additional information in CBOR was inspired by the
encoding of length information designed by <span class="contact-name">Klaus Hartke</span> for CoAP.<a href="#section-appendix.h-3" class="pilcrow">¶</a></p>
<p id="section-appendix.h-4">This document also incorporates suggestions made by many people,
notably <span class="contact-name">Dan Frost</span>, <span class="contact-name">James Manger</span>, 
<span class="contact-name">Jeffrey Yasskin</span>, <span class="contact-name">Joe Hildebrand</span>, 
<span class="contact-name">Keith Moore</span>, <span class="contact-name">Laurence Lundblade</span>, 
<span class="contact-name">Matthew Lepinski</span>, <span class="contact-name">Michael Richardson</span>,
<span class="contact-name">Nico Williams</span>, <span class="contact-name">Peter Occil</span>, 
<span class="contact-name">Phillip Hallam-Baker</span>, <span class="contact-name">Ray Polk</span>, 
<span class="contact-name">Stuart Cheshire</span>, <span class="contact-name">Tim Bray</span>,
<span class="contact-name">Tony Finch</span>, <span class="contact-name">Tony Hansen</span>, and 
<span class="contact-name">Yaron Sheffer</span>.  <span class="contact-name">Benjamin Kaduk</span> 
provided an extensive review during IESG processing.
<span class="contact-name">Éric Vyncke</span>, <span class="contact-name">Erik Kline</span>, 
<span class="contact-name">Robert Wilton</span>, and <span class="contact-name">Roman Danyliw</span> 
provided further IESG comments, which included an IoT directorate review by 
<span class="contact-name">Eve Schooler</span>.<a href="#section-appendix.h-4" class="pilcrow">¶</a></p>
</section>
</div>
<div id="authors-addresses">
<section id="section-appendix.i">
      <h2 id="name-authors-addresses">
<a href="#name-authors-addresses" class="section-name selfRef">Authors' Addresses</a>
      </h2>
<address class="vcard">
        <div dir="auto" class="left"><span class="fn nameRole">Carsten Bormann</span></div>
<div dir="auto" class="left"><span class="org">Universität Bremen TZI</span></div>
<div dir="auto" class="left"><span class="street-address">Postfach 330440</span></div>
<div dir="auto" class="left">
<span class="postal-code">D-28359</span> <span class="locality">Bremen</span>
</div>
<div dir="auto" class="left"><span class="country-name">Germany</span></div>
<div class="tel">
<span>Phone:</span>
<a href="tel:+49-421-218-63921" class="tel">+49-421-218-63921</a>
</div>
<div class="email">
<span>Email:</span>
<a href="mailto:cabo@tzi.org" class="email">cabo@tzi.org</a>
</div>
</address>
<address class="vcard">
        <div dir="auto" class="left"><span class="fn nameRole">Paul Hoffman</span></div>
<div dir="auto" class="left"><span class="org">ICANN</span></div>
<div class="email">
<span>Email:</span>
<a href="mailto:paul.hoffman@icann.org" class="email">paul.hoffman@icann.org</a>
</div>
</address>
</section>
</div>
<script>const toc = document.getElementById("toc");
toc.querySelector("h2").addEventListener("click", e => {
  toc.classList.toggle("active");
});
toc.querySelector("nav").addEventListener("click", e => {
  toc.classList.remove("active");
});
</script>
</body>
</html>

